package com.huazhi.wzsnw.controller;

import com.alibaba.fastjson.JSONArray;
import com.huazhi.wzsnw.constant.CommonUser;
import com.huazhi.wzsnw.exception.BusinessException;
import com.huazhi.wzsnw.exception.ErrorCode;
import com.huazhi.wzsnw.mapper.*;
import com.huazhi.wzsnw.model.*;
import com.huazhi.wzsnw.model.po.Dtree;
import com.huazhi.wzsnw.service.*;
import com.huazhi.wzsnw.util.KitFileUtil;
import com.alibaba.fastjson.JSONObject;
import org.apache.poi.util.StringUtil;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Generated;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

@Controller
@RequestMapping("/base")
public class BaseController {
    @Autowired
    PeasantService peasantService;
    @Autowired
    ArchivesService archivesService;
    @Autowired
    CircuitService circuitService;
    @Autowired
    MaintainRecordService maintainRecordService;
    @Autowired
    ServiceRecordService serviceRecordService;
    @Autowired
    ComplaintService complaintService;
    @Autowired
    TrainRecordService trainRecordService;
    @Autowired
    DossierService dossierService;
    @Autowired
    UserService userService;
    @Autowired
    LawService lawService;
    @Autowired
    AlertService alertService;
    @Autowired
    AlertMapper alertMapper;
    @Autowired
    LinedStateMapper linedStateMapper;
    @Autowired
    LinedMapper linedMapper;
    @Autowired
    LogService logService;
    @Autowired
    ImportExcelService importExcelService;
    @Autowired
    VillageMapper villageMapper;
    @Autowired
    XzzdServcie xzzdServcie;
    @Autowired
    ProAndXzMapper proAndXzMapper;
    @Autowired
    ProjectTableMapper projectTableMapper;
    @Autowired
    WxssMapper wxssMapper;
    @Autowired
    YhjlMapper yhjlMapper;
    @Autowired
    XcxjMapper xcxjMapper;
    @Autowired
    SzjcMapper szjcMapper;
    @Autowired
    DtuRecordMapper dtuRecordMapper;
    @Autowired
    DdlinedMapper ddlinedMapper;


    @InitBinder
    public void initBinder(WebDataBinder binder) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        dateFormat.setLenient(false);
        binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
    }

    @RequestMapping(value = "/getBaseExist", method = RequestMethod.POST)
    public ModelAndView getBaseExist(HttpServletRequest request, HttpSession httpSession) {
        try {
            String name = request.getParameter("name");
            String table = request.getParameter("field");
            String TID = peasantService.getByBaseName(name, table);
            if (TID == null) {
                return json(true);
            } else {
                return json(false);
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_SYSTEM_ROUTE);
        }
    }

    //村庄信息
    @RequestMapping(value = "/getListVillage", method = RequestMethod.GET)
    public ModelAndView getListVillage(HttpServletRequest request, HttpSession httpSession) {
        try {
            JSONObject jsonObject = new JSONObject();
            int total = 0;
            String page = request.getParameter("page");
            String limit = request.getParameter("limit");
            //List<String> list = new ArrayList<String>();
            List<String> list = peasantService.getListBaseTidByRequest(request, "village");
            Integer limits = Integer.valueOf(limit);
            Integer pages = Integer.valueOf(page);
            Integer pageIndex = (pages - 1) * limits;
            Integer pageSize = Integer.valueOf(limit);

            List chemicalApplications = new ArrayList<>();
            if (list.size() == 0) {
                jsonObject.put("data", false);
                jsonObject.put("count", 0);
                jsonObject.put("msg", "");
            } else {
                total = list.size();
                chemicalApplications = peasantService.findPagingByListTid(list, pageIndex, pageSize, "village");
                jsonObject.put("data", chemicalApplications);
                jsonObject.put("count", total);
                jsonObject.put("msg", "");
            }
            jsonObject.put("code", 0);
            logService.getAddLog("基本信息维护", "村委会名录管理", "查询信息");
            return json(jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_SYSTEM_ROUTE);
        }
    }

    //乡镇管理（zch）
    @RequestMapping(value = "/getXzglList", method = RequestMethod.GET)
    public ModelAndView getXzglList(HttpServletRequest request, HttpSession session) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("YYYY-MM-dd");
        JSONObject jsonObject = new JSONObject();
        String page = request.getParameter("page");
        String limit = request.getParameter("limit");
        String keyAll = request.getParameter("key");
        Integer limitInt = Integer.valueOf(limit);
        Integer pageInt = (Integer.valueOf(page) - 1) * limitInt;
        Integer total = 0;
//        List<String> listCount = peasantService.getListBaseTidByRequest(request,"village");
        List<Village> list = new ArrayList<>();
        if (request.getParameter("xzc") != null) {
            String key = request.getParameter("xzc");
            String newKey = key.substring(0, key.length() - 1).substring(1);
            total = villageMapper.selectByXzc(newKey, null, null).size();
            list = villageMapper.selectByXzc(newKey, pageInt, limitInt);
        } else {
            total = villageMapper.selectAllVillage(null, null, keyAll).size();
            list = villageMapper.selectAllVillage(pageInt, limitInt, keyAll);
        }
        for (Village v : list
        ) {
            if (v.getHushu() == null) {
                v.setHushuString("0户");
            } else {
                v.setHushuString(v.getHushu() + "户");
            }
            v.setCreateTimeString(simpleDateFormat.format(v.getCreatetime()));
        }
        jsonObject.put("data", list);
        jsonObject.put("count", total);
        jsonObject.put("msg", "");
        jsonObject.put("code", 0);
        logService.getAddLog("基本信息维护", "乡镇管理", "查询信息");
        return json(jsonObject);
    }

    @RequestMapping(value = "/xzgl/add", method = RequestMethod.POST)
    @Transactional
    public ModelAndView addXz(@RequestParam(value = "uploadImage") MultipartFile[] image, HttpServletRequest request) {
        Village village = new Village();
        String tid = UUID.randomUUID().toString();
        String name = request.getParameter("name");
        String cunweihui = request.getParameter("cunweihui");
        String zhen = request.getParameter("zhen");
        String hushu = request.getParameter("hushu");
        village.setTid(tid);
        if (request.getParameter("hushu") != null && !"".equals(request.getParameter("hushu"))) {
            village.setHushu(Integer.valueOf(hushu));
        }
        village.setZhen(zhen);
        village.setCunweihui(cunweihui);
        village.setName(name);
        village.setCreatetime(new Date());
        KitFileUtil kitFileUtil = new KitFileUtil();
        Map<String, Object> map = new HashMap();
        map = kitFileUtil.uploadFiles(image, "files", "xzgl", request);
        String path = map.get("path").toString();
        if (!path.equals("")) {
            village.setImage(path);
        }
        villageMapper.insertSelective(village);

        List<Xzzd> xzList = xzzdServcie.selectByTitle(village.getZhen());
        if (xzList.size() < 1) {
            int cwhPid = inserXzzd(-1, zhen);
            int zrcPid = inserXzzd(cwhPid, cunweihui);
            int a = inserXzzd(zrcPid, name);
        } else {
            List<Xzzd> cwhList = xzzdServcie.selectByTitle(cunweihui);
            if (cwhList.size() < 1) {
                int zrcPid = inserXzzd(xzList.get(0).getId(), cunweihui);
                int a = inserXzzd(zrcPid, name);
            } else {
                List<Xzzd> zrcList = xzzdServcie.selectByTitle(name);
                if (zrcList.size() < 1) {
                    int a = inserXzzd(cwhList.get(0).getId(), name);
                }
            }
        }
        logService.getAddLog("基本信息维护", "乡镇管理", "新增记录" + name);
        return json(true);
    }

    @RequestMapping(value = "/getLineByCunziForSzjc", method = {RequestMethod.GET, RequestMethod.POST})
    public ModelAndView getLineByCunziForSzjc(HttpServletRequest request) {
        String cun = request.getParameter("cun");
        Ddlined ddlined = ddlinedMapper.seletLineByCun(cun);
        if (ddlined == null) {
            Lined lined = linedMapper.seletLineByCun(cun);
            return json(lined);
        }
        return json(ddlined);
    }

    @RequestMapping(value = "/xzgl/PageAdd", method = {RequestMethod.GET, RequestMethod.POST})
    public ModelAndView xglPageAdd(HttpServletRequest request, HttpSession httpSession) {
        List<Xzzd> xzzdList = xzzdServcie.selectVyPid(-1);
        Map map = new HashMap();
        map.put("zhenList", xzzdList);
        if ("-2".equals(request.getParameter("xzId"))) {
            //什么也没选
            map.put("zhen", "no");
            map.put("cwh", "no");
            return json(map);
        } else {
            String xzId = request.getParameter("xzId");
            String xzParentId = request.getParameter("xzParentId");
            if ("-1".equals(xzParentId)) {
                xzParentId = "-1";
            }
            if (-1 == Integer.valueOf(xzParentId)) {
                //第一级
                Xzzd xz = xzzdServcie.selectById(Integer.valueOf(xzId));
                map.put("zhen", xz.getTitle());
                map.put("cwh", "no");
            } else {
                Xzzd xzzd = xzzdServcie.selectById(Integer.valueOf(xzParentId));
                if (-1 == xzzd.getPid()) {
                    //第二级
                    Xzzd cwh = xzzdServcie.selectById(Integer.valueOf(xzId));
                    map.put("zhen", xzzd.getTitle());
                    map.put("cwh", cwh.getTitle());
                } else {
                    //第三级
                    Xzzd zx = xzzdServcie.selectById(xzzd.getPid());
                    map.put("cwh", xzzd.getTitle());
                    map.put("zhen", zx.getTitle());
                }
            }
        }
        return json(map);
    }

    @RequestMapping(value = "/delxz", method = RequestMethod.POST)
    @Transactional
    public ModelAndView delxz(HttpServletRequest request) {
        try {
            String tid = request.getParameter("tid");
            Village village = (Village) peasantService.findBaseByTid(tid, "village");
            peasantService.deleteBase(tid, "village");
            List<Xzzd> list = xzzdServcie.selectByTitle(village.getName());
            xzzdServcie.deleteByTitle(village.getName());
            List<Xzzd> newList = xzzdServcie.selectVyPid(list.get(0).getPid());
            if (newList == null || newList.size() < 1) {
                Xzzd xzzd = xzzdServcie.selectById(list.get(0).getPid());
                xzzdServcie.deleteByTitle(xzzd.getTitle());
            }
            List<Xzzd> zhenList = xzzdServcie.selectByTitle(village.getZhen());
            if (zhenList != null && zhenList.size() > 0) {
                List<Xzzd> list1 = xzzdServcie.selectVyPid(zhenList.get(0).getId());
                if (list1 == null || list1.size() == 0) {
                    xzzdServcie.deleteByTitle(zhenList.get(0).getTitle());
                }
            }
            logService.getAddLog("基本信息维护", "乡镇管理", "删除记录" + village.getName());
            return json(true);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_SYSTEM_ROUTE);
        }
    }

    @RequestMapping(value = "/getCwhSelect", method = RequestMethod.POST)
    public ModelAndView getCwhSelect(HttpServletRequest request) {
        try {
            String xzName = request.getParameter("xzName");
            List<Xzzd> xzList = xzzdServcie.selectByTitle(xzName);
            Integer cwhPid = xzList.get(0).getId();
            List<Xzzd> cwhList = xzzdServcie.selectVyPid(cwhPid);
            Map map = new HashMap();
            map.put("cwhList", cwhList);
            return json(map);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_SYSTEM_ROUTE);
        }
    }

    @RequestMapping(value = "/circuitExport", method = RequestMethod.GET)
    public void circuitExport(HttpServletRequest request, HttpServletResponse response) throws IOException {
        String tid = request.getParameter("tid");
        Circuit circuit = circuitService.selectByPrimaryKey(tid);
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        FileInputStream fileInputStream = new FileInputStream("C:\\Users\\Administrator\\Desktop\\巡查导出模板.xlsx");
        XSSFWorkbook xssfWorkbook = new XSSFWorkbook(fileInputStream);
        XSSFSheet sheet = xssfWorkbook.getSheet("Sheet1");
        XSSFRow row = sheet.getRow(1);
        if (circuit.getXcrq() != null) {
            row.getCell(1).setCellValue(simpleDateFormat.format(circuit.getXcrq()));
        } else {
            row.getCell(1).setCellValue("");
        }
        row.getCell(3).setCellValue(circuit.getSbxh());
        row.getCell(5).setCellValue(circuit.getGzry());
        XSSFRow row1 = sheet.getRow(4);
        row1.getCell(0).setCellValue(circuit.getGd());
        row1.getCell(1).setCellValue(circuit.getTsb());
        row1.getCell(2).setCellValue(circuit.getCsb());
        row1.getCell(3).setCellValue(circuit.getFxb());
        row1.getCell(4).setCellValue(circuit.getJy());
        row1.getCell(5).setCellValue(circuit.getPd());
        row1.getCell(6).setCellValue(circuit.getXsp());
        row1.getCell(7).setCellValue(circuit.getLjg());
        XSSFRow row2 = sheet.getRow(5);
        row2.getCell(1).setCellValue(circuit.getBz());
        XSSFRow row3 = sheet.getRow(7);
        if (circuit.getSbwxrq() != null) {
            row3.getCell(1).setCellValue(simpleDateFormat.format(circuit.getSbwxrq()));
        } else {
            row3.getCell(1).setCellValue("");
        }
        row3.getCell(4).setCellValue(circuit.getSbwxry());
        XSSFRow row4 = sheet.getRow(8);
        row4.getCell(1).setCellValue(circuit.getGzms());
        XSSFRow row5 = sheet.getRow(9);
        row5.getCell(1).setCellValue(circuit.getXfqk());
        XSSFRow row6 = sheet.getRow(11);
        row6.getCell(1).setCellValue(circuit.getGwxcqk());
        row6.getCell(2).setCellValue(circuit.getGznr());
        OutputStream os = response.getOutputStream();
        response.setContentType("application/octet-stream");
        // 下载文件的默认名称
        String fileName = circuit.getXcrq() == null ? "" : simpleDateFormat.format(circuit.getXcrq()) + "巡查表";
        response.setCharacterEncoding("utf-8");
        response.setHeader("Content-disposition", "attachment;filename=" + new String(fileName.getBytes("gbk"), "iso8859-1") + ".xlsx");
        xssfWorkbook.write(os);
        os.flush();
        os.close();
    }

    public String getCellValue(String str) {
        String[] strs = str.split(",");
        String value = "";
        if (str == null) {
            return value;
        }
        for (String s : strs) {
            value = s + "\n";
        }
        return value;
    }

    @RequestMapping(value = "/checkXzName", method = {RequestMethod.GET, RequestMethod.POST})
    public ModelAndView checkXzName(HttpServletRequest request) {
        String name = request.getParameter("name");
        List<Village> list = villageMapper.slectByName(name);
        if (list != null && list.size() > 0) {
            return json(true);
        } else {
            return json(false);
        }
    }

    @RequestMapping(value = "/getXzByZrc", method = {RequestMethod.GET, RequestMethod.POST})
    public ModelAndView getXzByZrc(HttpServletRequest request) {
        String xzzdId = request.getParameter("zrcId");
        Xzzd xzzd = xzzdServcie.selectById(Integer.valueOf(xzzdId));
        List<Village> list = villageMapper.slectByName(xzzd.getTitle());
        Map map = new HashMap();
        if (list.size() > 0) {
            map.put("zrc", list.get(0));
        } else {
            map.put("zrc", null);
        }
        return json(map);
    }

    @RequestMapping(value = "/getXzglSelect", method = {RequestMethod.GET, RequestMethod.POST})
    public ModelAndView getXzglSelect(HttpServletRequest request) {
        try {
            String xzzdId = request.getParameter("xzzdId");
            Xzzd xzzd = xzzdServcie.selectById(Integer.valueOf(xzzdId));
            List<Xzzd> xzzdList = new ArrayList<>();
            if (-1 != Integer.valueOf(xzzdId)) {
                if (xzzd.getPid() != -1) {
                    List<Integer> prozrcIds = proAndXzMapper.selectXzIds();
                    if (prozrcIds.size() > 0) {
                        xzzdList = xzzdServcie.selctZxNotInIds(prozrcIds, Integer.valueOf(xzzdId));
                    } else {
                        xzzdList = xzzdServcie.selectVyPid(Integer.valueOf(xzzdId));
                    }
                } else {
                    xzzdList = xzzdServcie.selectVyPid(Integer.valueOf(xzzdId));
                }
            } else {
                xzzdList = xzzdServcie.selectVyPid(Integer.valueOf(xzzdId));
            }

            Map map = new HashMap();
            map.put("xzzdList", xzzdList);
            return json(map);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_SYSTEM_ROUTE);
        }
    }


    @RequestMapping(value = "/getXzTree", method = {RequestMethod.GET, RequestMethod.POST})
    public ModelAndView getXzTree(HttpServletRequest request) {
        try {
            List<Xzzd> list = xzzdServcie.selectAll();
            List<Dtree> dtreeList = new ArrayList<>();
            JSONObject jsonObject = new JSONObject();
            for (Xzzd xzzd : list) {
                Dtree dtree = new Dtree();
                dtree.setId(String.valueOf(xzzd.getId()));
                dtree.setCheckArr("0");
                dtree.setTitle(xzzd.getTitle());
                dtree.setParentId(String.valueOf(xzzd.getPid()));
                dtreeList.add(dtree);
            }
            jsonObject.put("data", dtreeList);
            jsonObject.put("msg", "操作成功");
            jsonObject.put("code", 0);
            return json(jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_SYSTEM_ROUTE);
        }
    }


    //存储乡镇数据
    private int inserXzzd(int pid, String title) {
        Xzzd xzzd = new Xzzd();
        xzzd.setPid(pid);
        xzzd.setTitle(title);
        xzzdServcie.insert(xzzd);
        List<Xzzd> list = xzzdServcie.selectByTitle(title);
        return list.get(0).getId();
    }


    @RequestMapping(value = "/getListWatercheck", method = RequestMethod.GET)
    public ModelAndView getListWatercheck(HttpServletRequest request, HttpSession httpSession) {
        try {

            JSONObject jsonObject = new JSONObject();
            int total = 0;
            String page = request.getParameter("page");
            String limit = request.getParameter("limit");
            List<String> list = peasantService.getListBaseTidByRequest(request, "shuizhi");
            Integer limits = Integer.valueOf(limit);
            Integer pages = Integer.valueOf(page);
            Integer pageIndex = (pages - 1) * limits;
            Integer pageSize = Integer.valueOf(limit);
            List chemicalApplications = new ArrayList<>();
            if (list.size() == 0) {
                jsonObject.put("data", false);
                jsonObject.put("count", 0);
                jsonObject.put("msg", "");
            } else {
                total = list.size();
                chemicalApplications = peasantService.findPagingByListTid(list, pageIndex, pageSize, "shuizhi");
                jsonObject.put("data", chemicalApplications);
                jsonObject.put("count", total);
                jsonObject.put("msg", "");
            }
            jsonObject.put("code", 0);
            logService.getAddLog("基本信息维护", "水量水质报告", "查询信息");
            return json(jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_SYSTEM_ROUTE);
        }
    }

    @RequestMapping(value = "/addWatercheck", method = RequestMethod.POST)
    public ModelAndView addWatercheck(@RequestParam(value = "uploadFile") MultipartFile[] files, HttpServletRequest request) {
        try {
            KitFileUtil kitFileUtil = new KitFileUtil();
            Map<String, Object> map = new HashMap<>();
            String cun = request.getParameter("cun");
            String checktime = request.getParameter("checktime");
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            ShuiZhi shuiZhi = new ShuiZhi();
            shuiZhi.setTid(UUID.randomUUID().toString());
            shuiZhi.setCun(cun);
            if (!"".equals(checktime)) {
                shuiZhi.setChecktime(dateFormat.parse(checktime));
            }
            shuiZhi.setOperator(request.getParameter("operator"));
            shuiZhi.setFlow(request.getParameter("flow"));
            shuiZhi.setPh(request.getParameter("ph"));
            shuiZhi.setDo(request.getParameter("do"));
            shuiZhi.setTransparency(request.getParameter("transparency"));
            shuiZhi.setSs(request.getParameter("ss"));
            shuiZhi.setCodcr(request.getParameter("codcr"));
            shuiZhi.setBod5(request.getParameter("bod5"));
            shuiZhi.setTp(request.getParameter("tp"));
            shuiZhi.setTn(request.getParameter("tn"));
            shuiZhi.setHn3N(request.getParameter("hn3N"));
            shuiZhi.setYield(request.getParameter("yield"));
            shuiZhi.setIconcentration(request.getParameter("iconcentration"));
            shuiZhi.setEconcentration(request.getParameter("econcentration"));
            shuiZhi.setConcentration(request.getParameter("concentration"));
            shuiZhi.setStandard(request.getParameter("standard"));
            shuiZhi.setCompliance(request.getParameter("compliance"));
            map = kitFileUtil.uploadFiles(files, "files", "shuizhi", request);
            String path = map.get("path").toString();
            if (!path.equals("")) {
                shuiZhi.setDocument(path);
            }
            shuiZhi.setState("0");
            shuiZhi.setInsertuser(CommonUser.getUser().getTid());
            shuiZhi.setInserttime(new Date());
            peasantService.saveBase(shuiZhi, "shuizhi");
            logService.getAddLog("基本信息维护", "水量水质报告", "新增记录" + cun);
            return json(true);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_ADD);
        }
    }

    @RequestMapping(value = "/updateWatercheck", method = {RequestMethod.POST, RequestMethod.GET})
    public ModelAndView updateWatercheck(@RequestParam(value = "uploadFile") MultipartFile[] files, HttpServletRequest request) {
        try {
            KitFileUtil kitFileUtil = new KitFileUtil();
            Map<String, Object> map = new HashMap<>();
            String checktime = request.getParameter("checktime");
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            ShuiZhi shuiZhi = (ShuiZhi) peasantService.findBaseByTid(request.getParameter("tid"), "shuizhi");
            shuiZhi.setCun(request.getParameter("cun"));
            if (!"".equals(checktime)) {
                shuiZhi.setChecktime(dateFormat.parse(checktime));
            }
            shuiZhi.setOperator(request.getParameter("operator"));
            shuiZhi.setFlow(request.getParameter("flow"));
            shuiZhi.setPh(request.getParameter("ph"));
            shuiZhi.setDo(request.getParameter("do"));
            shuiZhi.setTransparency(request.getParameter("transparency"));
            shuiZhi.setSs(request.getParameter("ss"));
            shuiZhi.setCodcr(request.getParameter("codcr"));
            shuiZhi.setBod5(request.getParameter("bod5"));
            shuiZhi.setTp(request.getParameter("tp"));
            shuiZhi.setTn(request.getParameter("tn"));
            shuiZhi.setHn3N(request.getParameter("hn3N"));
            shuiZhi.setYield(request.getParameter("yield"));
            shuiZhi.setIconcentration(request.getParameter("iconcentration"));
            shuiZhi.setEconcentration(request.getParameter("econcentration"));
            shuiZhi.setConcentration(request.getParameter("concentration"));
            shuiZhi.setStandard(request.getParameter("standard"));
            shuiZhi.setCompliance(request.getParameter("compliance"));
            String oldfiles = request.getParameter("oldfiles");
            map = kitFileUtil.uploadFiles(files, "files", "shuizhi", request);
            String path = map.get("path").toString();
            if (!path.equals("")) {
                if (!"".equals(oldfiles)) {
                    oldfiles = oldfiles + "," + path;
                } else {
                    oldfiles = path;
                }
            }
            shuiZhi.setDocument(oldfiles);
            peasantService.updateBase(shuiZhi, "shuizhi");
            logService.getAddLog("基本信息维护", "水量水质报告", "修改记录" + shuiZhi.getCunname());
            return json(true);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_UPDATE);
        }
    }

    @RequestMapping(value = "/getWatercheckByTid", method = {RequestMethod.POST, RequestMethod.GET})
    public ModelAndView getWatercheckByTid(HttpServletRequest request) {
        try {
            String tid = request.getParameter("tid");
            Object chemical = peasantService.findBaseByTid(tid, "shuizhi");
            ShuiZhi shuiZhi = (ShuiZhi) chemical;
            logService.getAddLog("基本信息维护", "水量水质报告", "查看" + shuiZhi.getCunname() + "详情");
            return json(chemical);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_SYSTEM_ROUTE);
        }
    }

    @RequestMapping(value = "/delWatercheck", method = RequestMethod.POST)
    public ModelAndView delWatercheck(HttpServletRequest request) {
        try {
            String tid = request.getParameter("tid");
            ShuiZhi shuiZhi = (ShuiZhi) peasantService.findBaseByTid(tid, "shuizhi");
            shuiZhi.setState("-1");
            peasantService.updateBase(shuiZhi, "shuizhi");
            logService.getAddLog("基本信息维护", "水量水质报告", "删除记录" + shuiZhi.getCunname());
            return json(true);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_DEL);
        }
    }

    @RequestMapping(value = "/addVillage", method = RequestMethod.POST)
    public ModelAndView addChemicalApplication(@RequestParam(value = "uploadImage") MultipartFile[] image, HttpServletRequest request) {
        try {
            String tid = UUID.randomUUID().toString();
            String name = request.getParameter("name");
            String cunweihui = request.getParameter("cunweihui");
            String jingdu = request.getParameter("jingdu");
            String weidu = request.getParameter("weidu");
            String zhen = request.getParameter("zhen");
            String xiang = request.getParameter("xiang");
            String address = request.getParameter("address");
            String contact = request.getParameter("contact");
            String contactphone = request.getParameter("contactphone");
            Map<String, Object> map = new HashMap<>();
            KitFileUtil kitFileUtil = new KitFileUtil();
            Village village = new Village();
            village.setTid(tid);
            village.setName(name);
            village.setCunweihui(cunweihui);
            village.setJingdu(jingdu);
            village.setWeidu(weidu);
            village.setZhen(zhen);
            village.setXiang(xiang);
            village.setAddress(address);
            village.setContact(contact);
            village.setContactphone(contactphone);
            village.setCreatetime(new Date());
            map = kitFileUtil.uploadFiles(image, "image", "village", request);
            String path = map.get("path").toString();
            if (!path.equals("")) {
                village.setImage(path);
            }
            peasantService.saveBase(village, "village");
            logService.getAddLog("基本信息维护", "村委会名录管理", "新增记录" + name);
            return json(true);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_ADD);
        }
    }

    @RequestMapping(value = "/updateVillage", method = {RequestMethod.POST, RequestMethod.GET})
    public ModelAndView updateVillage(@RequestParam(value = "uploadImage") MultipartFile[] image, HttpServletRequest request) {
        try {
            JSONObject jsonObject = new JSONObject();
            String tid = request.getParameter("tid");
            Village village = (Village) peasantService.findBaseByTid(tid, "village");
            String oldZrcName = village.getName();
            String oldCwhName = village.getCunweihui();
            String name = request.getParameter("name");
            String cunweihui = request.getParameter("cunweihui");
            String jingdu = request.getParameter("jingdu");
            String weidu = request.getParameter("weidu");
            String zhen = request.getParameter("zhen");
            String xiang = request.getParameter("xiang");
            String address = request.getParameter("address");
            String contact = request.getParameter("contact");
            String contactphone = request.getParameter("contactphone");
            String hushu = request.getParameter("hushu");
            Map<String, Object> map = new HashMap<>();
            KitFileUtil kitFileUtil = new KitFileUtil();
            village.setName(name);
            village.setCunweihui(cunweihui);
            village.setJingdu(jingdu);
            village.setWeidu(weidu);
            village.setZhen(zhen);
            village.setXiang(xiang);
            village.setAddress(address);
            village.setContact(contact);
            village.setContactphone(contactphone);
            if (request.getParameter("hushu") != null && !"".equals(request.getParameter("hushu"))) {
                village.setHushu(Integer.valueOf(hushu));
            }

            map = kitFileUtil.uploadFiles(image, "image", "village", request);
            String path = map.get("path").toString();
            if (!path.equals("")) {
                village.setImage(path);
            }

            peasantService.updateBase(village, "village");
            logService.getAddLog("基本信息维护", "乡镇管理", "修改记录" + name);
            List<Xzzd> xzList = xzzdServcie.selectByTitle(village.getZhen());
            xzzdServcie.deleteByTitle(oldZrcName);
            if (xzList.size() < 1) {
                int cwhPid = inserXzzd(-1, zhen);
                int zrcPid = inserXzzd(cwhPid, cunweihui);
                int a = inserXzzd(zrcPid, name);
            } else {
                List<Xzzd> cwhList = xzzdServcie.selectByTitle(cunweihui);
                if (cwhList.size() < 1) {
                    int zrcPid = inserXzzd(xzList.get(0).getId(), cunweihui);
                    int a = inserXzzd(zrcPid, name);
                } else {
                    List<Xzzd> zrcList = xzzdServcie.selectByTitle(name);
                    if (zrcList.size() < 1) {
                        int a = inserXzzd(cwhList.get(0).getId(), name);
                        xzzdServcie.deleteByTitle(oldZrcName);
                    }
                }

            }
            return json(true);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_UPDATE);
        }
    }


    @RequestMapping(value = "/getVillageByTid", method = {RequestMethod.POST, RequestMethod.POST})
    public ModelAndView getVillageByTid(HttpServletRequest request, HttpSession httpSession) {
        try {
            String tid = request.getParameter("tid");
            Object chemical = peasantService.findBaseByTid(tid, "village");
            Village village = (Village) chemical;
            logService.getAddLog("运维管理子系统", "村委会名录管理", "查看" + village.getName() + "详情");

            return json(chemical);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_SYSTEM_ROUTE);
        }
    }


    @RequestMapping(value = "/delVillage", method = RequestMethod.POST)
    public ModelAndView delVillage(HttpServletRequest request) {
        try {
            String tid = request.getParameter("tid");
            Village village = (Village) peasantService.findBaseByTid(tid, "village");
            peasantService.deleteBase(tid, "village");
            logService.getAddLog("基本信息维护", "村委会名录管理", "删除记录" + village.getName());
            return json(true);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_DEL);
        }
    }

    @RequestMapping(value = "/bindingVillage", method = RequestMethod.POST)
    public ModelAndView bindingVillage(HttpServletRequest request) {
        try {
            String tid = request.getParameter("tid");
            String number = request.getParameter("number");
            Village village = (Village) peasantService.findBaseByTid(tid, "village");
            Lined lined = new Lined();
            lined.setTid(UUID.randomUUID().toString());
            lined.setNumber(number);
            lined.setState("2");
            lined.setCun(village.getName());
            lined.setZhen(village.getZhen());
            lined.setJingdu(village.getJingdu());
            lined.setWeidu(village.getWeidu());
            lined.setXiang(village.getXiang());
            lined.setVideotid(request.getParameter("videotid"));
            lined.setVideoUrl(request.getParameter("videourl"));
            lined.setReason(tid);//村庄tid
            lined.setName(request.getParameter("sbname"));
            lined.setDunwei(request.getParameter("dunwei"));
            linedMapper.insertSelective(lined);//添加新的DTU记录
            LinedState linedState = linedStateMapper.getLinedStateByField("number", number.trim());
            linedState.setBinding("1");
            //将该DTU的状态修改为已绑定
            linedStateMapper.updateByPrimaryKeySelective(linedState);
            logService.getAddLog("基本信息维护", "村委会名录管理", village.getName() + "绑定DTU");
            return json(true);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_SYSTEM_ROUTE);
        }
    }

    @RequestMapping(value = "/bindingShebei", method = RequestMethod.POST)
    public ModelAndView bindingShebei(HttpServletRequest request) {
        try {
            String tid = request.getParameter("tid");
            String videotid = request.getParameter("videotid");
            String videourl = request.getParameter("videourl");
            String number = request.getParameter("number");
            Lined lined = (Lined) peasantService.findBaseByTid(tid, "lined");
//            if (null != videotid && !"".equals(videotid)) {
                lined.setVideotid(request.getParameter("videotid"));
//            }
//            if (null != videourl && !"".equals(videourl)) {
                lined.setVideoUrl(request.getParameter("videourl"));
//            }
            if (null != number && !"".equals(number)&& !"请选择".equals(number)) {
                lined.setNumber(number);
                LinedState linedState = linedStateMapper.getLinedStateByField("number", number.trim());
                linedState.setBinding("1");
                linedStateMapper.updateByPrimaryKeySelective(linedState);
                lined.setChanshuibengstrattime(linedState.getChanshuibengstrattime());
                lined.setChanshuibengendtime(linedState.getChanshuibengendtime());
                lined.setFanxibengstrattime(linedState.getFanxibengstrattime());
                lined.setFanxibengendtime(linedState.getFanxibengendtime());
                lined.setGufengjistrattime(linedState.getGufengjistrattime());
                lined.setGufengjiendtime(linedState.getGufengjiendtime());
                lined.setJiaobanjistrattime(linedState.getJiaobanjistrattime());
                lined.setJiaobanjiendtime(linedState.getJiaobanjiendtime());
                lined.setHuiliubengstarttime(linedState.getHuiliubengstarttime());
                lined.setHuiliubengendtime(linedState.getHuiliubengendtime());
                lined.setChanshuibeng(linedState.getChanshuibeng());
                lined.setHuiliubeng(linedState.getHuiliubeng());
                lined.setGufengji1(linedState.getGufengji1());
                lined.setGufengji2(linedState.getGufengji2());
                lined.setFanxibeng(linedState.getFanxibeng());
                lined.setJiaobanji(linedState.getJiaobanji());
                lined.setJinshuibeng(linedState.getJinshuibeng());
            }
            linedMapper.updateByPrimaryKeySelective(lined);
            logService.getAddLog("基本信息维护", "设备管理", lined.getName() + "绑定DTU");
            return json(true);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_SYSTEM_ROUTE);
        }
    }

    @RequestMapping(value = "/bindingddShebei", method = RequestMethod.POST)
    public ModelAndView bindingddShebei(HttpServletRequest request) {
        try {
            String tid = request.getParameter("tid");
            String videotid = request.getParameter("videotid");
            String videourl = request.getParameter("videourl");
            String number = request.getParameter("number");
            Ddlined lined = ddlinedMapper.selectByPrimaryKey(tid);
            if (null != videotid && !"".equals(videotid)) {
                lined.setVideotid(request.getParameter("videotid"));
            }
            if (null != videourl && !"".equals(videourl)) {
                lined.setVideourl(request.getParameter("videourl"));
            }
            if (null != number && !"".equals(number)) {
                lined.setNumber(number);
                LinedState linedState = linedStateMapper.getLinedStateByField("number", number.trim());
                linedState.setBinding("1");
                linedStateMapper.updateByPrimaryKeySelective(linedState);

            }
            ddlinedMapper.updateByPrimaryKeySelective(lined);
            logService.getAddLog("基本信息维护", "设备管理", lined.getName() + "绑定DTU");
            return json(true);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_SYSTEM_ROUTE);
        }
    }

    @RequestMapping(value = "/unboundVillage", method = RequestMethod.POST)
    public ModelAndView unboundVillage(HttpServletRequest request) {
        try {
            String tid = request.getParameter("tid");
            Lined lined = linedMapper.getLinedByField("reason", tid.trim());
            if (lined != null) {
                linedMapper.deleteByPrimaryKey(lined.getTid());
                LinedState linedState = linedStateMapper.getLinedStateByField("number", lined.getNumber().trim());
                if (linedState != null) {
                    linedState.setBinding("0");
                    //将该DTU的状态修改为未绑定
                    linedStateMapper.updateByPrimaryKeySelective(linedState);
                    logService.getAddLog("基本信息维护", "村委会名录管理", lined.getCun() + "解绑DTU");
                }
            }
            return json(true);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_SYSTEM_ROUTE);
        }
    }

    @RequestMapping(value = "/unboundShebei", method = RequestMethod.POST)
    public ModelAndView unboundShebei(HttpServletRequest request) {
        String tid = request.getParameter("tid");
        Lined lined = (Lined) peasantService.findBaseByTid(tid, "lined");
        LinedState linedState = linedStateMapper.getLinedStateByField("number", lined.getNumber().trim());
        lined.setNumber(null);
        linedMapper.updateByPrimaryKeySelective(lined);
        if (linedState != null) {
            linedState.setBinding("0");
            //将该DTU的状态修改为未绑定
            linedStateMapper.updateByPrimaryKeySelective(linedState);
            logService.getAddLog("基本信息维护", "设备管理", lined.getName() + "解绑DTU");
        }
        return json(true);
    }

    @RequestMapping(value = "/unboundddShebei", method = RequestMethod.POST)
    public ModelAndView unboundddShebei(HttpServletRequest request) {
        String tid = request.getParameter("tid");
        Ddlined lined = ddlinedMapper.selectByPrimaryKey(tid);
        LinedState linedState = linedStateMapper.getLinedStateByField("number", lined.getNumber().trim());
        lined.setVideotid("-1");
        lined.setVideourl("-1");
        ddlinedMapper.updateByPrimaryKeySelective(lined);
        if (linedState != null) {
            linedState.setBinding("0");
            //将该DTU的状态修改为未绑定
            linedStateMapper.updateByPrimaryKeySelective(linedState);
            logService.getAddLog("基本信息维护", "设备管理", lined.getName() + "解绑DTU");
        }
        return json(true);
    }


    @RequestMapping(value = "/getSelectVillage", method = RequestMethod.GET)
    public ModelAndView getSelectVillage(HttpServletRequest request) {
        try {
            List<String> list = peasantService.getListBaseTidByRequest(request, "village");
            JSONObject jsonObject = new JSONObject();
            List villages = new ArrayList<>();
            if (list.size() == 0) {
                jsonObject.put("data", false);
                jsonObject.put("count", 0);
                jsonObject.put("msg", "");
            } else {
                villages = peasantService.findPagingByListTid(list, null, null, "village");
                jsonObject.put("data", villages);
                jsonObject.put("count", villages.size());
                jsonObject.put("msg", "");
            }
            jsonObject.put("code", 0);
            return json(jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_ADD);
        }
    }


    //村民信息
    @RequestMapping(value = "/getListPeasant", method = RequestMethod.GET)
    public ModelAndView getListPeasant(HttpServletRequest request, HttpSession httpSession) {
        try {

            JSONObject jsonObject = new JSONObject();
            int total = 0;
            String page = request.getParameter("page");
            String limit = request.getParameter("limit");
            //List<String> list = new ArrayList<String>();
            List<String> list = peasantService.getListBaseTidByRequest(request, "peasant");
            Integer limits = Integer.valueOf(limit);
            Integer pages = Integer.valueOf(page);
            Integer pageIndex = (pages - 1) * limits;
            Integer pageSize = Integer.valueOf(limit);

            /*List<String> params = new ArrayList<String>();
            if ("".equals(search)) {
                params.add("");
            } else if (!"".equals(search) && search.indexOf(" ") != -1) {
                params = Arrays.asList(search.split(" "));
            } else if (!"".equals(search) && search.indexOf(" ") == -1) {
                params.add(search);
            }
            Boolean firstSearch = true;
            for (String oneParam : params) {
                if (firstSearch) {
                    list = peasantService.getListBaseTidBySearch(oneParam, "peasant");
                    firstSearch = false;
                } else {
                    List<String> middleList = peasantService.getListBaseTidBySearch(oneParam, "peasant");
                    list.retainAll(middleList);
                }
            }*/
            List chemicalApplications = new ArrayList<>();
            if (list.size() == 0) {
                jsonObject.put("data", false);
                jsonObject.put("count", 0);
                jsonObject.put("msg", "");
            } else {
                total = list.size();
                chemicalApplications = peasantService.findPagingByListTid(list, pageIndex, pageSize, "peasant");

                jsonObject.put("data", chemicalApplications);
                jsonObject.put("count", total);
                jsonObject.put("msg", "");
            }
            jsonObject.put("code", 0);
            logService.getAddLog("基本信息维护", "农户信息管理", "查询信息");
            return json(jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_SYSTEM_ROUTE);
        }
    }

    @RequestMapping(value = "/addPeasant", method = RequestMethod.POST)
    public ModelAndView addPeasant(HttpServletRequest request, HttpSession httpSession) {
        try {
//            User user=(User)httpSession.getAttribute("userInfo");
            String tid = UUID.randomUUID().toString();
            String name = request.getParameter("name");
            String phone = request.getParameter("phone");
            Integer peoplecount = Integer.valueOf(request.getParameter("peopleCount"));
            String watertype = request.getParameter("waterType");
            String cun = request.getParameter("cun");
            String isconnection = request.getParameter("isConnection");
            String projectname = request.getParameter("projectName");
            String cunName = request.getParameter("cunName");
            Peasant peasant = new Peasant();
//            Village village = (Village)peasantService.findBaseByTid(cun,"village");
//            if(cun!=null && !"".equals(cun)){
//                List<String> tids = peasantService.getBaseTidByName(cun,"village");
//                if(tids!=null&&!tid.isEmpty()){
//                    peasant.setCun(tids.get(0));
//                }
//            }
            peasant.setTid(tid);
            peasant.setCun(cun);
            peasant.setIsconnection(isconnection);
            peasant.setPhone(phone);
            peasant.setName(name);
            peasant.setProjectname(projectname);
            peasant.setCunname(cunName);
            if (!"".equals(projectname) && projectname != null) {
                List<String> tids = peasantService.getBaseTidByName(projectname, "projectTable");
                if (!tids.isEmpty()) {
                    peasant.setProjecttid(tids.get(0));
                }
            }
            peasant.setWatertype(watertype);
            peasant.setPeoplecount(peoplecount);
            peasant.setCreatetime(new Timestamp(System.currentTimeMillis()));
            peasantService.saveBase(peasant, "peasant");
            logService.getAddLog("基本信息维护", "农户信息管理", "新增记录" + name);
            return json(true);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_ADD);
        }
    }

    @RequestMapping(value = "/getPeasantByTid", method = {RequestMethod.POST, RequestMethod.GET})
    public ModelAndView getPeasantByTid(HttpServletRequest request, HttpSession httpSession) {
        try {
            String tid = request.getParameter("tid");
            Object chemical = peasantService.findBaseByTid(tid, "peasant");
            Peasant peasant = (Peasant) chemical;
            logService.getAddLog("基本信息维护", "农户信息管理", "查看" + peasant.getName() + "详情");
            return json(chemical);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_SYSTEM_ROUTE);
        }
    }

    @RequestMapping(value = "/updatePeasant", method = RequestMethod.POST)
    public ModelAndView updatePeasant(HttpServletRequest request) {
        try {
            String tid = request.getParameter("tid");
            String projectname = request.getParameter("projectname");
            Peasant peasant = (Peasant) peasantService.findBaseByTid(tid, "peasant");
            peasant.setName(request.getParameter("name"));
            peasant.setPhone(request.getParameter("phone"));
            peasant.setPeoplecount(Integer.valueOf(request.getParameter("peoplecount")));
            peasant.setWatertype(request.getParameter("watertype"));
            peasant.setCun(request.getParameter("cun"));
            peasant.setIsconnection(request.getParameter("isconnection"));
            peasant.setProjectname(projectname);
            peasant.setCunname(request.getParameter("cunname"));
            if (!"".equals(projectname) && projectname != null) {
                List<String> tids = peasantService.getBaseTidByName(projectname, "projectTable");
                if (!tids.isEmpty()) {
                    peasant.setProjecttid(tids.get(0));
                }
            }
            peasant.setCreatetime(new Timestamp(System.currentTimeMillis()));
            logService.getAddLog("基本信息维护", "农户信息管理", "修改记录" + peasant.getName());
            peasantService.updateBase(peasant, "peasant");
            return json(true);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_UPDATE);
        }
    }

    @RequestMapping(value = "/delPeasant", method = RequestMethod.POST)
    public ModelAndView delPeasant(HttpServletRequest request) {
        try {
            String tid = request.getParameter("tid");
            Peasant peasant = (Peasant) peasantService.findBaseByTid(tid, "peasant");
            peasantService.deleteBase(tid, "peasant");
            logService.getAddLog("基本信息维护", "农户信息管理", "删除记录" + peasant.getName());
            return json(true);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_DEL);
        }
    }

    //项目管理
    @RequestMapping(value = "/getListProjectTable", method = RequestMethod.GET)
    public ModelAndView getListProjectTable(HttpServletRequest request) {
        try {
            JSONObject jsonObject = new JSONObject();
            String page = request.getParameter("page");
            String limit = request.getParameter("limit");
            List<String> list = peasantService.getListBaseTidByRequest(request, "projectTable");
            int limits = Integer.parseInt(limit);
            int pages = Integer.parseInt(page);
            Integer pageIndex = (pages - 1) * limits;
            Integer pageSize = Integer.valueOf(limit);
            List projectTable = new ArrayList();
            if (list == null || list.isEmpty()) {
                jsonObject.put("data", false);
                jsonObject.put("count", 0);
                jsonObject.put("msg", "");
            } else {

                projectTable = peasantService.findPagingByListTid(list, pageIndex, pageSize, "projectTable");
                List<ProjectTable> newList = new ArrayList<>();
                for (Object obj : projectTable) {
                    ProjectTable projectTable1 = (ProjectTable) obj;
                    projectTable1.setZjDateString(getStringByDate(projectTable1.getZjDate()));
                    projectTable1.setStarDateString(getStringByDate(projectTable1.getStarDate()));
                    projectTable1.setEnDateString(getStringByDate(projectTable1.getEnDate()));
                    projectTable1.setYsDateString(getStringByDate(projectTable1.getYsDate()));
                    projectTable1.setTcDateString(getStringByDate(projectTable1.getTcDate()));

                    List<Integer> xzIds = proAndXzMapper.selectByProId(projectTable1.getTid());
                    if (xzIds.size() > 0) {
                        String str = "";
                        List<Xzzd> xzzdList = xzzdServcie.selectByIds(xzIds);
                        for (Xzzd xzzd : xzzdList) {
                            str = str + xzzd.getTitle() + ",";
                        }
                        projectTable1.setXmszc(str);
                    }
                    newList.add(projectTable1);
                }
                jsonObject.put("data", newList);
                jsonObject.put("count", list.size());
                jsonObject.put("msg", "");
            }
            jsonObject.put("code", 0);
            logService.getAddLog("基本信息维护", "项目信息管理", "查询信息");
            return json(jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_SYSTEM_ROUTE);
        }
    }

    @RequestMapping(value = "/getProXZ", method = RequestMethod.POST)
    public ModelAndView getProXZ(HttpServletRequest request) {
        try {
            String tid = request.getParameter("tid");
            List<Integer> xzids = proAndXzMapper.selectByProId(tid);
            Map map = new HashMap();
            List<Village> villages = new ArrayList<>();
            if (xzids.size() > 0) {
                for (Integer xzId : xzids) {
                    Xzzd xzzd = xzzdServcie.selectById(xzId);
                    List<Village> villages1 = villageMapper.slectByName(xzzd.getTitle());
                    villages1.get(0).setZrcId(xzId);
                    villages.add(villages1.get(0));
                }
                map.put("list", villages);
            } else {
                map.put("list", villages);
            }
            return json(map);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_SYSTEM_ROUTE);
        }
    }


    private String getStringByDate(Date date) {
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        if (date != null) {
            return dateFormat.format(date);
        } else {
            return null;
        }
    }

    @RequestMapping(value = "/addProjectTable", method = RequestMethod.POST)
    public ModelAndView addProjectTable(HttpServletRequest request) {
        try {
            ProjectTable projectTable = new ProjectTable();
            String peopelcount = request.getParameter("peopelcount");
            String investmentscale = request.getParameter("investmentscale");
            projectTable.setTid(UUID.randomUUID().toString());
            projectTable.setName(request.getParameter("name"));
            projectTable.setUnit(request.getParameter("unit"));
            projectTable.setDetail(request.getParameter("detail"));
//            if(!"".equals(peopelcount)){
//                projectTable.setPeopelcount(Integer.parseInt(peopelcount));
//            }
            projectTable.setScope(request.getParameter("scope"));
            projectTable.setMaterial(request.getParameter("material"));
            projectTable.setLocation(request.getParameter("location"));
            projectTable.setOperationunit(request.getParameter("operationunit"));
            projectTable.setOperationperson(request.getParameter("operationperson"));
            projectTable.setOperationphone(request.getParameter("operationphone"));
            projectTable.setResponsible(request.getParameter("responsible"));
            projectTable.setPipecover(request.getParameter("pipecover"));
            projectTable.setStandard(request.getParameter("standard"));
//            if(!"".equals(investmentscale)){
//                projectTable.setInvestmentscale(Double.parseDouble(investmentscale));
//            }
            projectTable.setPipelayingroute(request.getParameter("pipeLayingroute"));
            projectTable.setPipedirection(request.getParameter("pipedirection"));
            projectTable.setPipescopo(request.getParameter("pipescopo"));
            projectTable.setCspfbz(request.getParameter("cspfbz"));
            projectTable.setGylccl(request.getParameter("gylccl"));
            projectTable.setSyrk(request.getParameter("syrk"));
            projectTable.setPwk(request.getParameter("pwk"));
            projectTable.setFsgdcd(request.getParameter("fsgdcd"));
            projectTable.setGl(request.getParameter("gl"));
            projectTable.setHfc(request.getParameter("hfc"));
            projectTable.setWspx(request.getParameter("wspx"));
            projectTable.setJd(request.getParameter("jd"));
            projectTable.setWd(request.getParameter("wd"));
            projectTable.setSbyxqk(request.getParameter("sbyxqk"));
            projectTable.setSbcj(request.getParameter("sbcj"));
            projectTable.setRcll(request.getParameter("rcll"));
            projectTable.setXmbz(request.getParameter("xmbz"));

            if (request.getParameter("starDateString") != null && !request.getParameter("starDateString").equals("")) {
                projectTable.setStarDate(getDateByString(request.getParameter("starDateString")));

            }
            if (request.getParameter("enDateString") != null && !request.getParameter("enDateString").equals("")) {
                projectTable.setEnDate(getDateByString(request.getParameter("enDateString")));
            }

            if (request.getParameter("tcDateString") != null && !request.getParameter("tcDateString").equals("")) {
                projectTable.setTcDate(getDateByString(request.getParameter("tcDateString")));
            }
            if (request.getParameter("ysDateString") != null && !request.getParameter("ysDateString").equals("")) {
                projectTable.setYsDate(getDateByString(request.getParameter("ysDateString")));
            }
            if (request.getParameter("zjDateString") != null && !request.getParameter("zjDateString").equals("")) {
                projectTable.setZjDate(getDateByString(request.getParameter("zjDateString")));
            }

            String zrcids = request.getParameter("zrcids");
            if (!"".equals(zrcids)) {
                String[] split = zrcids.split("-");
                List<Integer> zrcList = new ArrayList<>();
                for (int i = 0; i < split.length; i++) {
                    zrcList.add(Integer.valueOf(split[i]));
                }
                proAndXzMapper.insertByxzIdAndProId(projectTable.getTid(), zrcList);
            }
            peasantService.saveBase(projectTable, "projectTable");

            logService.getAddLog("基本信息维护", "项目信息管理", "新增记录" + projectTable.getName());
            return json(true);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_ADD);
        }
    }

    private Date getDateByString(String dateString) throws ParseException {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        if (dateString == null) {
            return null;
        } else {
            return simpleDateFormat.parse(dateString);
        }
    }

    @RequestMapping(value = "/getProjectTableByTid", method = RequestMethod.GET)
    public ModelAndView getProjectTableByTid(HttpServletRequest request, HttpSession httpSession) {
        try {
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            String tid = request.getParameter("tid");
            Object projectTable = peasantService.findBaseByTid(tid, "projectTable");
            ProjectTable projectTable1 = (ProjectTable) projectTable;
            if (projectTable1.getTcDate() != null) {
                projectTable1.setTcDateString(simpleDateFormat.format(projectTable1.getTcDate()));
            }
            if (projectTable1.getYsDate() != null) {
                projectTable1.setYsDateString(simpleDateFormat.format(projectTable1.getYsDate()));
            }
            if (projectTable1.getEnDate() != null) {
                projectTable1.setEnDateString(simpleDateFormat.format(projectTable1.getEnDate()));
            }
            if (projectTable1.getStarDate() != null) {
                projectTable1.setStarDateString(simpleDateFormat.format(projectTable1.getStarDate()));
            }
            if (projectTable1.getZjDate() != null) {
                projectTable1.setZjDateString(simpleDateFormat.format(projectTable1.getZjDate()));
            }


            logService.getAddLog("基本信息维护", "项目信息管理", "查看" + projectTable1.getName() + "详情");
            return json(projectTable1);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_SYSTEM_ROUTE);
        }
    }

    @RequestMapping(value = "/updateProjectTable", method = RequestMethod.POST)
    public ModelAndView updateProjectTable(HttpServletRequest request) {
        try {
            String peopelcount = request.getParameter("peopelcount");
            String investmentscale = request.getParameter("investmentscale");
            String tid = request.getParameter("tid");
            ProjectTable projectTable = (ProjectTable) peasantService.findBaseByTid(tid, "projectTable");
            projectTable.setName(request.getParameter("name"));
            projectTable.setUnit(request.getParameter("unit"));
            projectTable.setDetail(request.getParameter("detail"));
            projectTable.setScope(request.getParameter("scope"));
            projectTable.setMaterial(request.getParameter("material"));
            projectTable.setLocation(request.getParameter("location"));
            projectTable.setOperationunit(request.getParameter("operationunit"));
            projectTable.setOperationperson(request.getParameter("operationperson"));
            projectTable.setOperationphone(request.getParameter("operationphone"));
            projectTable.setResponsible(request.getParameter("responsible"));
            projectTable.setPipecover(request.getParameter("pipecover"));
            projectTable.setStandard(request.getParameter("standard"));
            projectTable.setPipelayingroute(request.getParameter("pipeLayingroute"));
            projectTable.setPipedirection(request.getParameter("pipedirection"));
            projectTable.setPipescopo(request.getParameter("pipescope"));
            projectTable.setCspfbz(request.getParameter("cspfbz"));
            projectTable.setGylccl(request.getParameter("gylccl"));
            projectTable.setSyrk(request.getParameter("syrk"));
            projectTable.setPwk(request.getParameter("pwk"));
            projectTable.setFsgdcd(request.getParameter("fsgdcd"));
            projectTable.setGl(request.getParameter("gl"));
            projectTable.setHfc(request.getParameter("hfc"));
            projectTable.setWspx(request.getParameter("wspx"));
            projectTable.setJd(request.getParameter("jd"));
            projectTable.setWd(request.getParameter("wd"));
            projectTable.setSbyxqk(request.getParameter("sbyxqk"));
            projectTable.setSbcj(request.getParameter("sbcj"));
            projectTable.setRcll(request.getParameter("rcll"));
            projectTable.setXmbz(request.getParameter("xmbz"));
//            projectTable.setStarDate(getDateByString(request.getParameter("starDateString")));
//            projectTable.setEnDate(getDateByString(request.getParameter("enDateString")));
//            projectTable.setTcDate(getDateByString(request.getParameter("tcDateString")));
//            projectTable.setYsDate(getDateByString(request.getParameter("ysDateString")));
//            projectTable.setZjDate(getDateByString(request.getParameter("zjDateString")));
            if (request.getParameter("starDateString") != null && !request.getParameter("starDateString").equals("")) {
                projectTable.setStarDate(getDateByString(request.getParameter("starDateString")));

            }
            if (request.getParameter("enDateString") != null && !request.getParameter("enDateString").equals("")) {
                projectTable.setEnDate(getDateByString(request.getParameter("enDateString")));
            }

            if (request.getParameter("tcDateString") != null && !request.getParameter("tcDateString").equals("")) {
                projectTable.setTcDate(getDateByString(request.getParameter("tcDateString")));
            }
            if (request.getParameter("ysDateString") != null && !request.getParameter("ysDateString").equals("")) {
                projectTable.setYsDate(getDateByString(request.getParameter("ysDateString")));
            }
            if (request.getParameter("zjDateString") != null && !request.getParameter("zjDateString").equals("")) {
                projectTable.setZjDate(getDateByString(request.getParameter("zjDateString")));
            }
            proAndXzMapper.deleteByProId(tid);
            String zrcids = request.getParameter("zrcids");
            if (!"".equals(zrcids)) {
                String[] split = zrcids.split("-");
                List<Integer> zrcList = new ArrayList<>();
                for (int i = 0; i < split.length; i++) {
                    zrcList.add(Integer.valueOf(split[i]));
                }
                proAndXzMapper.insertByxzIdAndProId(projectTable.getTid(), zrcList);
            }
            peasantService.updateBase(projectTable, "projectTable");
            logService.getAddLog("基本信息维护", "项目信息管理", "修改记录" + projectTable.getName());
            return json(true);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_ADD);
        }
    }

    @RequestMapping(value = "/delProjectTable", method = RequestMethod.POST)
    public ModelAndView delProjectTable(HttpServletRequest request) {
        try {
            String tid = request.getParameter("tid");
            ProjectTable projectTable = (ProjectTable) peasantService.findBaseByTid(tid, "projectTable");
            proAndXzMapper.deleteByProId(tid);
            peasantService.deleteBase(tid, "projectTable");
            logService.getAddLog("基本信息维护", "项目信息管理", "删除记录" + projectTable.getName());
            return json(true);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_DEL);
        }
    }

    //巡查巡检记录
    @RequestMapping(value = "/getListCircuit", method = RequestMethod.GET)
    public ModelAndView getVenuesList(HttpServletRequest request) {
        try {
            JSONObject jsonObject = circuitService.getCircuitListOne(request);
            logService.getAddLog("运维记录与台账管理", "巡查巡检记录", "查询信息");
            return json(jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_SYSTEM_ROUTE);
        }
    }


    @RequestMapping(value = "/getCircuitTj", method = RequestMethod.GET)
    public ModelAndView getCircuitTj(HttpServletRequest request) throws ParseException {
        Circuit circuit = new Circuit();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-mm-dd");
        String xz = request.getParameter("xz");
        String zrc = request.getParameter("zrc");
        String cwh = request.getParameter("cwh");
        String sxStaDate = request.getParameter("sxStaDate");
        String sxEndDate = request.getParameter("sxEndDate");
        if (sxStaDate != null && !"".equals(sxStaDate)) {
            circuit.setSxStaDate(sxStaDate);
        }
        if (sxEndDate != null && !"".equals(sxEndDate)) {
            circuit.setSxEndDate(sxEndDate);
        }
        if (xz != null && !"".equals(xz)) {
            if (!xz.startsWith("请选择")) {
                circuit.setXz(xz);
            }

        }
        if (cwh != null && !"".equals(cwh)) {
            if (!cwh.startsWith("请选择")) {
                circuit.setCwh(cwh);
            }

        }
        if (zrc != null && !"".equals(zrc)) {
            if (!zrc.startsWith("请选择")) {
                circuit.setZrc(zrc);
            }
        }
        List<CurcuitTj> list = circuitService.sleletongji(circuit);
        Map map = new HashMap();
        map.put("code", 0);
        map.put("data", list);
        return json(map);
    }

//    @RequestMapping(value = "/getCircuit",method = RequestMethod.GET)
//    public ModelAndView getCircuit(HttpServletRequest request){
//        try {
//            Circuit circuit = new Circuit();
//            circuit.setIndoorfacilities(request.getParameter("indoorfacilities"));
//            List<String> list = circuitService.getCircuitList(null,circuit);
//            if(list.isEmpty()){
//                return json(true);
//            }else {
//                return json(false);
//            }
//        }catch (Exception e) {
//            e.printStackTrace();
//            throw new BusinessException(ErrorCode.ERROR_SYSTEM_ROUTE);
//        }
//    }

    @RequestMapping(value = "/getUserList", method = RequestMethod.GET)
    public ModelAndView getUserList(HttpServletRequest request) {
        try {
            List<User> list = userService.getUserList();
            return json(list);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_SYSTEM_ROUTE);
        }
    }

    @RequestMapping(value = "/getZrcs", method = RequestMethod.POST)
    public ModelAndView getZrcs(HttpServletRequest request) {
        String xzzdId = request.getParameter("xzzdId");
        List<Xzzd> list = xzzdServcie.selectVyPid(Integer.valueOf(xzzdId));
        Map map = new HashMap();
        map.put("xzzdList", list);
        return json(map);
    }

    @RequestMapping(value = "/xzwh", method = RequestMethod.POST)
    public ModelAndView xzwh(HttpServletRequest request, HttpServletResponse response) {
        String xzId = request.getParameter("xzId");
        String cwhId = request.getParameter("cwhId");
        String zrcId = request.getParameter("zrcId");
        Cookie cookie = new Cookie("xzId", xzId);
        Cookie cookie1 = new Cookie("cwhId", cwhId);
        Cookie cookie2 = new Cookie("zrcId", zrcId);
        response.addCookie(cookie);
        response.addCookie(cookie1);
        response.addCookie(cookie2);
        return json(true);

    }

    //返回手机日历
    @RequestMapping(value = "/whxc", method = RequestMethod.POST)
    public ModelAndView whxc(HttpServletRequest request, HttpServletResponse response) {
        String xcZrcId = request.getParameter("xcZrcId");
        Cookie cookie = new Cookie("xcZrcId", xcZrcId);
        response.addCookie(cookie);
        return json(true);
    }

    //巡查时间数组
    @RequestMapping(value = "/getDateArray", method = RequestMethod.GET)
    public ModelAndView getDateArray(HttpServletRequest request) {
        Cookie[] cookies = request.getCookies();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        List<String> list = new ArrayList<>();
        Map map = new HashMap();
        String zrcId = null;
        for (Cookie cookie : cookies) {
            if ("xcZrcId".equals(cookie.getName())) {
                zrcId = cookie.getValue();
            }
        }
        if (zrcId != null) {
            Xzzd xzzd = xzzdServcie.selectById(Integer.valueOf(zrcId));
            List<Date> dates = circuitService.selectXcDate(xzzd.getTitle());
            for (Date date : dates) {
                list.add(simpleDateFormat.format(date));
            }
            map.put("dates", list);
            return json(map);
        } else {
            map.put("dates", null);
            return json(map);
        }
    }

    //巡查时间数组
    @RequestMapping(value = "/getAllDateArray", method = RequestMethod.GET)
    public ModelAndView getAllDateArray(HttpServletRequest request) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        List<String> list = new ArrayList<>();
        Map map = new HashMap();
        List<Date> dates = circuitService.selectXcDate(null);
        for (Date date : dates) {
            list.add(simpleDateFormat.format(date));
        }

        map.put("dates", list);
        return json(map);
    }

    @RequestMapping(value = "/getlistByDatePage", method = RequestMethod.POST)
    public ModelAndView getlistByDatePage(HttpServletRequest request, HttpServletResponse response) {
        String slectDateByDate = request.getParameter("slectDateByDate");
        Cookie cookie = new Cookie("slectDateByDate", slectDateByDate);
        response.addCookie(cookie);
        return json(true);
    }

    @RequestMapping(value = "/getPageBySelctId", method = RequestMethod.POST)
    public ModelAndView getPageBySelctId(HttpServletRequest request, HttpServletResponse response) {
        String selectTid = request.getParameter("selectTid");
        Cookie cookie = new Cookie("selectTid", selectTid);
        response.addCookie(cookie);
        return json(true);
    }


    @RequestMapping(value = "/getInfoPage", method = RequestMethod.POST)
    public ModelAndView getInfoPage(HttpServletRequest request, HttpServletResponse response) {
        String infoDate = request.getParameter("infoDate");
        Cookie cookie = new Cookie("infoDate", infoDate);
        response.addCookie(cookie);
        return json(true);
    }

    @RequestMapping(value = "/getPhoneList", method = RequestMethod.GET)
    public ModelAndView getPhoneList(HttpServletRequest request) throws ParseException {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-mm-dd");
        Cookie[] cookies = request.getCookies();
        String date = null;
        for (Cookie cookie : cookies) {
            if ("slectDateByDate".equals(cookie.getName())) {
                date = cookie.getValue();
            }
        }
        Map map = new HashMap();
        map.put("code", 0);
        if (date != null) {
            List<Circuit> list = circuitService.seleByXcrq(date);
            map.put("data", list);
        } else {
            map.put("data", null);
        }
        return json(map);
    }

    @RequestMapping(value = "/getCuByDate", method = RequestMethod.GET)
    public ModelAndView getCuByDate(HttpServletRequest request) throws ParseException {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Cookie[] cookies = request.getCookies();
        String date = null;
        for (Cookie cookie : cookies) {
            if ("infoDate".equals(cookie.getName())) {
                date = cookie.getValue();
            }
        }
        if (date != null) {
//           Circuit circuit = circuitService.seleByXcrq(simpleDateFormat.parse(date));
//           if(circuit.getZrc()!= null && !"".equals(circuit.getZrc())){
//               List<Xzzd> xzzds = xzzdServcie.selectByTitle(circuit.getZrc());
//               circuit.setZrc(String.valueOf(xzzds.get(0).getId()));
//           }
//            if(circuit.getCwh()!= null && !"".equals(circuit.getCwh())){
//                List<Xzzd> xzzds = xzzdServcie.selectByTitle(circuit.getCwh());
//                circuit.setCwh(String.valueOf(xzzds.get(0).getId()));
//            }
//            if(circuit.getXz()!= null && !"".equals(circuit.getXz())){
//                List<Xzzd> xzzds = xzzdServcie.selectByTitle(circuit.getXz());
//                circuit.setXz(String.valueOf(xzzds.get(0).getId()));
//            }
//            if(circuit.getXcrq()!= null){
//               circuit.setXcrqString(simpleDateFormat.format(circuit.getXcrq()));
//            }
//            if(circuit.getSbwxrq()!=null){
//                circuit.setSbwxrqString(simpleDateFormat.format(circuit.getSbwxrq()));
//            }
            return json(null);
        } else {
            return json(null);
        }
    }


    @RequestMapping(value = "/getCuBySelectId", method = RequestMethod.GET)
    public ModelAndView getCuBySelectId(HttpServletRequest request) throws ParseException {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Cookie[] cookies = request.getCookies();
        String tid = null;
        for (Cookie cookie : cookies) {
            if ("selectTid".equals(cookie.getName())) {
                tid = cookie.getValue();
            }
        }
        if (tid != null) {
            Circuit circuit = circuitService.selectByPrimaryKey(tid);
            if (circuit.getZrc() != null && !"".equals(circuit.getZrc())) {
                List<Xzzd> xzzds = xzzdServcie.selectByTitle(circuit.getZrc());
                circuit.setZrc(String.valueOf(xzzds.get(0).getId()));
            }
            if (circuit.getCwh() != null && !"".equals(circuit.getCwh())) {
                List<Xzzd> xzzds = xzzdServcie.selectByTitle(circuit.getCwh());
                circuit.setCwh(String.valueOf(xzzds.get(0).getId()));
            }
            if (circuit.getXz() != null && !"".equals(circuit.getXz())) {
                List<Xzzd> xzzds = xzzdServcie.selectByTitle(circuit.getXz());
                circuit.setXz(String.valueOf(xzzds.get(0).getId()));
            }
            if (circuit.getXcrq() != null) {
                circuit.setXcrqString(simpleDateFormat.format(circuit.getXcrq()));
            }
            if (circuit.getSbwxrq() != null) {
                circuit.setSbwxrqString(simpleDateFormat.format(circuit.getSbwxrq()));
            }
            return json(circuit);
        } else {
            return json(null);
        }
    }

    @RequestMapping(value = "/getSlelctId", method = RequestMethod.GET)
    public ModelAndView getSlelctId(HttpServletRequest request) {
        Cookie[] cookies = request.getCookies();
        Map map = new HashMap();
        for (Cookie c : cookies) {
            if ("xzId".equals(c.getName())) {
                map.put("xzId", c.getValue());
            }
            if ("cwhId".equals(c.getName())) {
                map.put("cwhId", c.getValue());
            }
            if ("zrcId".equals(c.getName())) {
                map.put("zrcId", c.getValue());
            }
        }
        return json(map);
    }

    @RequestMapping(value = "/addCircuit", method = RequestMethod.POST)
    public ModelAndView addCircuit(@RequestParam(value = "uploadImage") MultipartFile[] image, HttpServletRequest request) {
        try {
            Circuit circuit = new Circuit();
            Map<String, Object> map = new HashMap<>();
            KitFileUtil kitFileUtil = new KitFileUtil();
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            circuit.setTid(UUID.randomUUID().toString());
            map = kitFileUtil.uploadFiles(image, "image", "cirunt", request);
            String path = map.get("path").toString();
            if (!path.equals("")) {
                circuit.setImgurl(path);
            }
            String xcrqString = request.getParameter("xcrqString");
            if (!"".equals(xcrqString)) {
                circuit.setXcrq(format.parse(xcrqString));
            }
            String sbwxrqString = request.getParameter("sbwxrqString");
            if (!"".equals(sbwxrqString)) {
                circuit.setSbwxrq(format.parse(sbwxrqString));
            }
            String xzId = request.getParameter("xz");
            String cwhId = request.getParameter("cwh");
            String zrcId = request.getParameter("zrc");
            Xzzd zhen = xzzdServcie.selectById(Integer.valueOf(xzId));
            Xzzd cuh = xzzdServcie.selectById(Integer.valueOf(cwhId));
            Xzzd zrc = xzzdServcie.selectById(Integer.valueOf(zrcId));
            circuit.setXz(zhen.getTitle());
            circuit.setCwh(cuh.getTitle());
            circuit.setZrc(zrc.getTitle());
            circuit.setSbxh(request.getParameter("sbxh"));
            circuit.setGzry(request.getParameter("gzry"));
            circuit.setGd(request.getParameter("gd"));
            circuit.setTsb(request.getParameter("tsb"));
            circuit.setCsb(request.getParameter("csb"));
            circuit.setJy(request.getParameter("jy"));
            circuit.setPd(request.getParameter("pd"));
            circuit.setXsp(request.getParameter("xsp"));
            circuit.setLjg(request.getParameter("ljg"));
            circuit.setGznr(request.getParameter("gznr"));
            circuit.setSbwxry(request.getParameter("sbwxry"));
            circuit.setGzms(request.getParameter("gzms"));
            circuit.setXfqk(request.getParameter("xfqk"));
            circuit.setGwxcqk(request.getParameter("gwxcqk"));
            circuit.setBz(request.getParameter("bz"));
            circuit.setFxb(request.getParameter("fxb"));
            circuit.setSewagenetworks(request.getParameter("sewagenetworks"));
            circuit.setSewagedisposal(request.getParameter("sewagedisposal"));
            circuit.setAuxiliaryfacilities(request.getParameter("auxiliaryfacilities"));
            circuit.setIndoorfacilities(request.getParameter("indoorfacilities"));

            circuitService.insert(circuit);
            logService.getAddLog("运维记录与台账管理", "巡查巡检记录", "新增记录" + circuit.getSewagenetworks());
            return json(true);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_ADD);
        }
    }

    @RequestMapping(value = "/getCircuitByTid", method = RequestMethod.GET)
    public ModelAndView getCircuitByTid(HttpServletRequest request) {
        try {
            Circuit circuit = circuitService.findByTid(request.getParameter("tid"));
            if (circuit.getXz() != null && !"".equals(circuit.getXz())) {
                List<Xzzd> xzzds = xzzdServcie.selectByTitle(circuit.getXz());
                circuit.setXz(String.valueOf(xzzds.get(0).getId()));
            }
            if (circuit.getCwh() != null && !"".equals(circuit.getCwh())) {
                List<Xzzd> xzzds = xzzdServcie.selectByTitle(circuit.getCwh());
                circuit.setCwh(String.valueOf(xzzds.get(0).getId()));
            }
            if (circuit.getZrc() != null && !"".equals(circuit.getZrc())) {
                List<Xzzd> xzzds = xzzdServcie.selectByTitle(circuit.getZrc());
                circuit.setZrc(String.valueOf(xzzds.get(0).getId()));
            }
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-mm-dd");
            if (null != circuit.getSbwxrq()) {
                circuit.setSbwxrqString(simpleDateFormat.format(circuit.getSbwxrq()));
            }
            if (null != circuit.getXcrq()) {
                circuit.setXcrqString(simpleDateFormat.format(circuit.getXcrq()));
            }
            logService.getAddLog("运维记录与台账管理", "巡查巡检记录", "查看" + circuit.getSewagenetworks() + "详情");
            return json(circuit);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_SYSTEM_ROUTE);
        }
    }

    @RequestMapping(value = "/updateCircuit", method = RequestMethod.POST)
    public ModelAndView updateCircuit(@RequestParam(value = "uploadImage") MultipartFile[] image, HttpServletRequest request) {
        try {
            Circuit circuit = circuitService.findByTid(request.getParameter("tid"));
            Map<String, Object> map = new HashMap<>();
            KitFileUtil kitFileUtil = new KitFileUtil();
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            map = kitFileUtil.uploadFiles(image, "image", "cirunt", request);
            String path = map.get("path").toString();
            if (!path.equals("")) {
                circuit.setImgurl(path);
            }
            String xcrqString = request.getParameter("xcrqString");
            if (!"".equals(xcrqString)) {
                circuit.setXcrq(format.parse(xcrqString));
            }
            String sbwxrqString = request.getParameter("sbwxrqString");
            if (!"".equals(sbwxrqString)) {
                circuit.setSbwxrq(format.parse(sbwxrqString));
            }
            String xzId = request.getParameter("xz");
            String cwhId = request.getParameter("cwh");
            String zrcId = request.getParameter("zrc");
            Xzzd zhen = xzzdServcie.selectById(Integer.valueOf(xzId));
            Xzzd cuh = xzzdServcie.selectById(Integer.valueOf(cwhId));
            Xzzd zrc = xzzdServcie.selectById(Integer.valueOf(zrcId));
            circuit.setXz(zhen.getTitle());
            circuit.setCwh(cuh.getTitle());
            circuit.setZrc(zrc.getTitle());
            circuit.setSbxh(request.getParameter("sbxh"));
            circuit.setGzry(request.getParameter("gzry"));
            circuit.setGd(request.getParameter("gd"));
            circuit.setTsb(request.getParameter("tsb"));
            circuit.setCsb(request.getParameter("csb"));
            circuit.setJy(request.getParameter("jy"));
            circuit.setPd(request.getParameter("pd"));
            circuit.setXsp(request.getParameter("xsp"));
            circuit.setLjg(request.getParameter("ljg"));
            circuit.setGznr(request.getParameter("gznr"));
            circuit.setSbwxry(request.getParameter("sbwxry"));
            circuit.setGzms(request.getParameter("gzms"));
            circuit.setXfqk(request.getParameter("xfqk"));
            circuit.setGwxcqk(request.getParameter("gwxcqk"));
            circuit.setBz(request.getParameter("bz"));
            circuit.setFxb(request.getParameter("fxb"));
            circuit.setSewagenetworks(request.getParameter("sewagenetworks"));
            circuit.setSewagedisposal(request.getParameter("sewagedisposal"));
            circuit.setAuxiliaryfacilities(request.getParameter("auxiliaryfacilities"));
            circuit.setIndoorfacilities(request.getParameter("indoorfacilities"));
            circuitService.update(circuit);
            logService.getAddLog("运维记录与台账管理", "巡查巡检记录", "修改记录" + circuit.getSewagenetworks());
            return json(true);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_UPDATE);
        }
    }

    @RequestMapping(value = "/delCircuit", method = RequestMethod.POST)
    public ModelAndView delCircuit(HttpServletRequest request) {
        try {
            Circuit circuit = circuitService.findByTid(request.getParameter("tid"));
            circuitService.delete(circuit);
            logService.getAddLog("运维记录与台账管理", "巡查巡检记录", "删除记录" + circuit.getSewagenetworks());
            return json(true);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_DEL);
        }
    }

    //养护记录
    @RequestMapping(value = "/getMaintainRecordList", method = RequestMethod.GET)
    public ModelAndView getMaintainRecordList(Model model, HttpServletRequest request) {
        try {
            JSONObject jsonObject = maintainRecordService.getMaintainRecordListOne(request);
            logService.getAddLog("运维记录与台账管理", "养护记录", "查询信息");
            return json(jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_SYSTEM_ROUTE);
        }
    }

    //    @RequestMapping(value = "/getMaintainRecord",method = RequestMethod.GET)
//    public ModelAndView getMaintainRecord(Model model,HttpServletRequest request){
//        try {
//            MaintainRecord maintainRecord = new MaintainRecord();
//            maintainRecord.setMaintainproject(request.getParameter("maintainproject"));
//            List<String> list = maintainRecordService.selectMaintainRecordList(null,maintainRecord);
//            if(list.isEmpty()){
//                return json(true);
//            }else {
//                return json(false);
//            }
//        }catch (Exception e) {
//            e.printStackTrace();
//            throw new BusinessException(ErrorCode.ERROR_SYSTEM_ROUTE);
//        }
//    }
    @RequestMapping(value = "/addMaintainRecord", method = RequestMethod.POST)
    public ModelAndView addMaintainRecord(@RequestParam(value = "uploadImage") MultipartFile[] image, HttpServletRequest request) {
        try {
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            KitFileUtil kitFileUtil = new KitFileUtil();
            Map<String, Object> map = new HashMap<>();
            String path = null;
            MaintainRecord maintainRecord = new MaintainRecord();
            maintainRecord.setTid(UUID.randomUUID().toString());
            maintainRecord.setMaintaindate(dateFormat.parse(request.getParameter("maintaindate")));
//            maintainRecord.setTime(dateFormat.parse(request.getParameter("time")));
            maintainRecord.setNaturalname(request.getParameter("naturalname"));
            maintainRecord.setDevicenum(Integer.parseInt(request.getParameter("devicenum")));
            maintainRecord.setMaintainproject(request.getParameter("maintainproject"));
            maintainRecord.setMaintainstate(request.getParameter("maintainstate"));
            maintainRecord.setMaintainuser(request.getParameter("maintainuser"));
            maintainRecord.setState("0");
            map = kitFileUtil.uploadFiles(image, "image", "maintainrecord", request);
            path = map.get("path").toString();
            if (!path.equals("")) {
                maintainRecord.setImage(path);
            }
            maintainRecordService.insert(maintainRecord);
            logService.getAddLog("运维记录与台账管理", "养护记录", "新增记录" + maintainRecord.getMaintaindatestring());
            return json(true);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_ADD);
        }
    }

    @RequestMapping(value = "/getMaintainRecordByTid", method = RequestMethod.GET)
    public ModelAndView getMaintainRecordByTid(Model model, HttpServletRequest request) {
        try {
            MaintainRecord maintainRecord = maintainRecordService.findByTid(request.getParameter("tid"));
            logService.getAddLog("运维记录与台账管理", "养护记录", "查看" + maintainRecord.getCunName() + "详情");
            return json(maintainRecord);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_SYSTEM_ROUTE);
        }
    }

    @RequestMapping(value = "/updateMaintainRecord", method = RequestMethod.POST)
    public ModelAndView updateMaintainRecord(@RequestParam(value = "uploadImage") MultipartFile[] image, HttpServletRequest request) {
        try {
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            KitFileUtil kitFileUtil = new KitFileUtil();
            Map<String, Object> map = new HashMap<>();
            String path = null;
            MaintainRecord maintainRecord = maintainRecordService.findByTid(request.getParameter("tid"));
            maintainRecord.setMaintaindate(dateFormat.parse(request.getParameter("maintaindate")));
//            maintainRecord.setTime(dateFormat.parse(request.getParameter("time")));
            maintainRecord.setNaturalname(request.getParameter("naturalname"));
            maintainRecord.setDevicenum(Integer.parseInt(request.getParameter("devicenum")));
            maintainRecord.setMaintainproject(request.getParameter("maintainproject"));
            maintainRecord.setMaintainstate(request.getParameter("maintainstate"));
            map = kitFileUtil.uploadFiles(image, "image", "maintainrecord", request);
            path = map.get("path").toString();
            if (!path.equals("")) {
                maintainRecord.setImage(path);
            }
            maintainRecordService.update(maintainRecord);
            logService.getAddLog("运维记录与台账管理", "养护记录", "修改记录" + maintainRecord.getCunName());
            return json(true);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_ADD);
        }
    }

    @RequestMapping(value = "/delMaintainRecord", method = RequestMethod.POST)
    public ModelAndView delMaintainRecord(HttpServletRequest request) {
        try {
            MaintainRecord maintainRecord = maintainRecordService.findByTid(request.getParameter("tid"));
            maintainRecord.setState("-1");
            maintainRecordService.update(maintainRecord);
            logService.getAddLog("运维记录与台账管理", "养护记录", "删除记录" + maintainRecord.getCunName());
            return json(true);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_DEL);
        }
    }

    //维修记录
    @RequestMapping(value = "/getListServiceRecord", method = RequestMethod.GET)
    public ModelAndView getServiceRecordList(Model model, HttpServletRequest request) {
        try {
            JSONObject jsonObject = serviceRecordService.getServiceRecordListOne(request);
            logService.getAddLog("运维记录与台账管理", "维修记录", "查询信息");
            return json(jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_SYSTEM_ROUTE);
        }
    }

    //    @RequestMapping(value = "/getServiceRecord",method = RequestMethod.GET)
//    public ModelAndView getServiceRecord(Model model,HttpServletRequest request){
//        try {
//            ServiceRecord serviceRecord = new ServiceRecord();
//            serviceRecord.setNaturalname(request.getParameter("naturalname"));
//            List<String> list = serviceRecordService.selectServiceRecordList(null,serviceRecord);
//            if(list.isEmpty()){
//                return json(true);
//            }else {
//                return json(false);
//            }
//        }catch (Exception e) {
//            e.printStackTrace();
//            throw new BusinessException(ErrorCode.ERROR_SYSTEM_ROUTE);
//        }
//    }
    @RequestMapping(value = "/addServiceRecord", method = RequestMethod.POST)
    public ModelAndView addServiceRecord(HttpServletRequest request) {
        try {
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            ServiceRecord serviceRecord = new ServiceRecord();
            serviceRecord.setTid(UUID.randomUUID().toString());
            serviceRecord.setServicedate(dateFormat.parse(request.getParameter("servicedate")));
//            serviceRecord.setTime(dateFormat.parse(request.getParameter("time")));
            serviceRecord.setNaturalname(request.getParameter("naturalname"));
            serviceRecord.setDevicenum(request.getParameter("devicenum"));
            serviceRecord.setServiceproject(request.getParameter("serviceproject"));
            serviceRecord.setServiceway(request.getParameter("serviceway"));
            serviceRecord.setServicestate(request.getParameter("servicestate"));
            serviceRecord.setServiceuser(request.getParameter("serviceuser"));
            serviceRecord.setState("0");
            serviceRecordService.insert(serviceRecord);
            logService.getAddLog("运维记录与台账管理", "维修记录", "新增记录" + serviceRecord.getServicedatestring());
            return json(true);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_ADD);
        }
    }

    @RequestMapping(value = "/getServiceRecordByTid", method = RequestMethod.GET)
    public ModelAndView getServiceRecordByTid(Model model, HttpServletRequest request) {
        try {
            ServiceRecord serviceRecord = serviceRecordService.findByTid(request.getParameter("tid"));
            logService.getAddLog("运维记录与台账管理", "维修记录", "查看" + serviceRecord.getCunname() + "详情");
            return json(serviceRecord);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_SYSTEM_ROUTE);
        }
    }

    @RequestMapping(value = "/updateServiceRecord", method = RequestMethod.POST)
    public ModelAndView updateServiceRecord(HttpServletRequest request) {
        try {
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            ServiceRecord serviceRecord = serviceRecordService.findByTid(request.getParameter("tid"));
            serviceRecord.setServicedate(dateFormat.parse(request.getParameter("servicedate")));
//            serviceRecord.setTime(dateFormat.parse(request.getParameter("time")));
            serviceRecord.setNaturalname(request.getParameter("naturalname"));
            serviceRecord.setDevicenum(request.getParameter("devicenum"));
            serviceRecord.setServiceproject(request.getParameter("serviceproject"));
            serviceRecord.setServiceway(request.getParameter("serviceway"));
            serviceRecord.setServicestate(request.getParameter("servicestate"));
            serviceRecord.setServiceuser(request.getParameter("serviceuser"));
            serviceRecordService.update(serviceRecord);
            logService.getAddLog("运维记录与台账管理", "维修记录", "修改记录" + serviceRecord.getCunname());
            return json(true);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_ADD);
        }
    }

    @RequestMapping(value = "/delServiceRecord", method = RequestMethod.POST)
    public ModelAndView delServiceRecord(HttpServletRequest request) {
        try {
            ServiceRecord serviceRecord = serviceRecordService.findByTid(request.getParameter("tid"));
            serviceRecord.setState("-1");
            serviceRecordService.update(serviceRecord);
            logService.getAddLog("运维记录与台账管理", "维修记录", "删除记录" + serviceRecord.getCunname());
//            serviceRecordService.delete(serviceRecord);
            return json(true);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_DEL);
        }
    }

    //投诉反馈记录表
    @RequestMapping(value = "/getListComplaint", method = RequestMethod.GET)
    public ModelAndView getComplaintList(Model model, HttpServletRequest request) {
        try {
            JSONObject jsonObject = complaintService.getComplaintListOne(request);
            logService.getAddLog("运维记录与台账管理", "投诉反馈记录", "查询信息");
            return json(jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_SYSTEM_ROUTE);
        }
    }

    //    @RequestMapping(value = "/getComplaint",method = RequestMethod.GET)
//    public ModelAndView getComplaint(Model model,HttpServletRequest request){
//        try {
//            Complaint complaint = new Complaint();
//            complaint.setPhenomenon(request.getParameter("phenomenon"));
//            List<String> list = complaintService.getComplaintList(null,complaint);
//            if(list.isEmpty()){
//                return json(true);
//            }else {
//                return json(false);
//            }
//        }catch (Exception e) {
//            e.printStackTrace();
//            throw new BusinessException(ErrorCode.ERROR_SYSTEM_ROUTE);
//        }
//    }
    @RequestMapping(value = "/addComplaint", method = RequestMethod.POST)
    public ModelAndView addComplaint(HttpServletRequest request) {
        try {
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Complaint complaint = new Complaint();
            String time = request.getParameter("time");
            String feedbacktime = request.getParameter("feedbacktime");
            complaint.setTid(UUID.randomUUID().toString());
            complaint.setPlace(request.getParameter("place"));
            if (!"".equals(time)) {
                complaint.setTime(dateFormat.parse(time));
            }
            complaint.setPhenomenon(request.getParameter("phenomenon"));
            if (!"".equals(feedbacktime)) {
                complaint.setFeedbacktime(dateFormat.parse(feedbacktime));
            }
            complaint.setQuestionresult(request.getParameter("questionresult"));
            complaintService.insert(complaint);
            logService.getAddLog("运维记录与台账管理", "投诉反馈记录", "新增记录" + complaint.getTimestring());
            return json(true);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_ADD);
        }
    }

    @RequestMapping(value = "/getComplaintByTid", method = RequestMethod.GET)
    public ModelAndView getComplaintByTid(Model model, HttpServletRequest request) {
        try {
            Complaint complaint = complaintService.findByTid(request.getParameter("tid"));
            logService.getAddLog("运维记录与台账管理", "投诉反馈记录", "查看详情");
            return json(complaint);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_SYSTEM_ROUTE);
        }
    }

    @RequestMapping(value = "/updateComplaint", method = RequestMethod.POST)
    public ModelAndView updateComplaint(HttpServletRequest request) {
        try {
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String time = request.getParameter("timestring");
            String feedbacktime = request.getParameter("feedbacktimestring");
            Complaint complaint = complaintService.findByTid(request.getParameter("tid"));
            complaint.setPlace(request.getParameter("place"));
            if (!"".equals(time)) {
                complaint.setTime(dateFormat.parse(time));
            }
            complaint.setPhenomenon(request.getParameter("phenomenon"));
            if (!"".equals(feedbacktime)) {
                complaint.setFeedbacktime(dateFormat.parse(feedbacktime));
            }
            complaint.setQuestionresult(request.getParameter("questionresult"));
            complaintService.update(complaint);
            logService.getAddLog("运维记录与台账管理", "投诉反馈记录", "修改记录" + complaint.getPhenomenon());
            return json(true);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_ADD);
        }
    }

    @RequestMapping(value = "/delComplaint", method = RequestMethod.POST)
    public ModelAndView delComplaint(HttpServletRequest request) {
        try {
            Complaint complaint = complaintService.findByTid(request.getParameter("tid"));
            logService.getAddLog("运维记录与台账管理", "投诉反馈记录", "删除记录" + complaint.getPhenomenon());
            complaintService.delete(complaint);
            return json(true);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_DEL);
        }
    }

    //培训记录表
    @RequestMapping(value = "/getTrainRecordList", method = RequestMethod.GET)
    public ModelAndView getTrainRecordList(Model model, HttpServletRequest request) {
        try {
            JSONObject jsonObject = trainRecordService.getTrainrecordListOne(request);
            logService.getAddLog("运维记录与台账管理", "培训记录", "查询信息");
            return json(jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_SYSTEM_ROUTE);
        }
    }

    //    @RequestMapping(value = "/getTrainRecord",method = RequestMethod.GET)
//    public ModelAndView getTrainRecord(Model model,HttpServletRequest request){
//        try {
//            Trainrecord trainrecord = new Trainrecord();
//            trainrecord.setPlace(request.getParameter("place"));
//            List<String> list = trainRecordService.getTrainRecordList(null,trainrecord);
//            if(list.isEmpty()){
//                return json(true);
//            }else {
//                return json(false);
//            }
//        }catch (Exception e) {
//            e.printStackTrace();
//            throw new BusinessException(ErrorCode.ERROR_SYSTEM_ROUTE);
//        }
//    }
    @RequestMapping(value = "/addTrainRecord", method = RequestMethod.POST)
    public ModelAndView addTrainRecord(@RequestParam(value = "uploadImage") MultipartFile[] imgfile,
                                       @RequestParam(value = "uploadVideo") MultipartFile[] videofile, HttpServletRequest request) {
        try {
            KitFileUtil kitFileUtil = new KitFileUtil();
            Map<String, Object> map = new HashMap<>();
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Trainrecord trainrecord = new Trainrecord();
            String path = null;
            trainrecord.setTid(UUID.randomUUID().toString());
            trainrecord.setPlace(request.getParameter("place"));
            trainrecord.setTime(dateFormat.parse(request.getParameter("time")));
            trainrecord.setSpeaker(request.getParameter("speaker"));
            trainrecord.setTraintheme(request.getParameter("traintheme"));
            trainrecord.setMeetingsign(request.getParameter("meetingsign"));
            map = kitFileUtil.uploadFiles(imgfile, "image", "trainrecord", request);
            path = map.get("path").toString();
            if (!path.equals("")) {
                trainrecord.setImage(path);
            }
            map = kitFileUtil.uploadFiles(videofile, "video", "trainrecord", request);
            path = map.get("path").toString();
            if (!path.equals("")) {
                trainrecord.setVideo(path);
            }
            trainRecordService.insert(trainrecord);
            logService.getAddLog("运维记录与台账管理", "培训记录", "新增记录" + trainrecord.getTraintheme());
            return json(true);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_ADD);
        }
    }

    @RequestMapping(value = "/getTrainRecordByTid", method = RequestMethod.GET)
    public ModelAndView getTrainRecordByTid(Model model, HttpServletRequest request) {
        try {
            Trainrecord trainrecord = trainRecordService.findByTid(request.getParameter("tid"));
            logService.getAddLog("运维记录与台账管理", "培训记录", "查看" + trainrecord.getTraintheme() + "详情");
            return json(trainrecord);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_SYSTEM_ROUTE);
        }
    }

    @RequestMapping(value = "/updateTrainRecord", method = RequestMethod.POST)
    public ModelAndView updateTrainRecord(@RequestParam(value = "uploadImage") MultipartFile[] imgfile,
                                          @RequestParam(value = "uploadVideo") MultipartFile[] videofile, HttpServletRequest request) {
        try {
            KitFileUtil kitFileUtil = new KitFileUtil();
            Map<String, Object> map = new HashMap<>();
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Trainrecord trainrecord = trainRecordService.findByTid(request.getParameter("tid"));
            String path = null;
            trainrecord.setPlace(request.getParameter("place"));
            trainrecord.setTime(dateFormat.parse(request.getParameter("time")));
            trainrecord.setSpeaker(request.getParameter("speaker"));
            trainrecord.setTraintheme(request.getParameter("traintheme"));
            trainrecord.setMeetingsign(request.getParameter("meetingsign"));
            map = kitFileUtil.uploadFiles(imgfile, "image", "trainrecord", request);
            path = map.get("path").toString();
            if (!path.equals("")) {
                trainrecord.setImage(path);
            }
            map = kitFileUtil.uploadFiles(videofile, "video", "trainrecord", request);
            path = map.get("path").toString();
            if (!path.equals("")) {
                trainrecord.setVideo(path);
            }
            trainRecordService.update(trainrecord);
            logService.getAddLog("运维记录与台账管理", "培训记录", "修改记录" + trainrecord.getTraintheme());
            return json(true);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_ADD);
        }
    }

    @RequestMapping(value = "/delTrainRecord", method = RequestMethod.POST)
    public ModelAndView delTrainRecord(HttpServletRequest request) {
        try {
            Trainrecord trainrecord = trainRecordService.findByTid(request.getParameter("tid"));
            logService.getAddLog("运维记录与台账管理", "培训记录", "删除记录" + trainrecord.getTraintheme());
            trainRecordService.delete(trainrecord);
            return json(true);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_DEL);
        }
    }

    //档案管理规章制度
    @RequestMapping(value = "/getListArchives", method = RequestMethod.GET)
    public ModelAndView getListArchives(HttpServletRequest request) {
        try {
            JSONObject jsonObject = archivesService.getArchivesListOne(request);
            logService.getAddLog("档案管理", "档案管理规章制度", "查询信息");
            return json(jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_SYSTEM_ROUTE);
        }
    }

    //    @RequestMapping(value = "/getArchives",method = RequestMethod.GET)
//    public ModelAndView getArchives(HttpServletRequest request){
//        try {
//            Archives archives = new Archives();
//            archives.setStipulate(request.getParameter("stipulate"));
//            List<String> list = archivesService.selectArchivesList(null,archives);
//            if(list.isEmpty()){
//                return json(true);
//            }else {
//                return json(false);
//            }
//        }catch (Exception e) {
//            e.printStackTrace();
//            throw new BusinessException(ErrorCode.ERROR_SYSTEM_ROUTE);
//        }
//    }
    @RequestMapping(value = "/addArchives", method = RequestMethod.POST)
    public ModelAndView addArchives(HttpServletRequest request) {
        try {
            Archives archives = new Archives();
            archives.setTid(UUID.randomUUID().toString());
            archives.setStipulate(request.getParameter("stipulate"));
            archives.setSystem(request.getParameter("system"));
            archivesService.insert(archives);
            logService.getAddLog("档案管理", "档案管理规章制度", "新增记录" + archives.getStipulate());
            return json(true);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_ADD);
        }
    }

    @RequestMapping(value = "/getArchivesByTid", method = RequestMethod.GET)
    public ModelAndView getArchivesByTid(HttpServletRequest request) {
        try {
            Archives archives = archivesService.findByTid(request.getParameter("tid"));
            logService.getAddLog("档案管理", "档案管理规章制度", "查看" + archives.getStipulate() + "详情");
            return json(archives);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_SYSTEM_ROUTE);
        }
    }

    @RequestMapping(value = "/updateArchives", method = RequestMethod.POST)
    public ModelAndView updateTrainRecord(HttpServletRequest request) {
        try {
            Archives archives = archivesService.findByTid(request.getParameter("tid"));
            archives.setStipulate(request.getParameter("stipulate"));
            archives.setSystem(request.getParameter("system"));
            archivesService.update(archives);
            logService.getAddLog("档案管理", "档案管理规章制度", "修改记录" + archives.getStipulate());
            return json(true);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_ADD);
        }
    }

    @RequestMapping(value = "/delArchives", method = RequestMethod.POST)
    public ModelAndView delArchives(HttpServletRequest request) {
        try {
            Archives archives = archivesService.findByTid(request.getParameter("tid"));
            archivesService.delete(archives);
            logService.getAddLog("档案管理", "档案管理规章制度", "删除记录" + archives.getStipulate());
            return json(true);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_DEL);
        }
    }

    //法律法规与政策
    @RequestMapping(value = "/getLawList", method = RequestMethod.GET)
    public ModelAndView getLawList(HttpServletRequest request) {
        try {
            JSONObject jsonObject = new JSONObject();
            List<String> list = lawService.getSearchLawListByRequest(request);
            int pageSize = Integer.parseInt(request.getParameter("limit"));
            int pages = Integer.parseInt(request.getParameter("page"));
            Integer pageIndex = (pages - 1) * pageSize;
            if (list.isEmpty()) {
                jsonObject.put("data", false);
                jsonObject.put("count", 0);
                jsonObject.put("msg", "");
            } else {
                List<Law> lawList = lawService.findPagingByListTid(list, pageIndex, pageSize);
                if (!lawList.isEmpty()) {
                    for (Law law : lawList) {
                        User user = userService.findByTid(law.getCreateby());
                        if (user != null) {
                            law.setCreateby(user.getName());
                        }
                    }
                }
                jsonObject.put("data", lawList);
                jsonObject.put("count", list.size());
                jsonObject.put("msg", "");
            }
            jsonObject.put("code", 0);
            logService.getAddLog("法律法规与政策", "法律法规与政策", "查询信息");
            return json(jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_SYSTEM_ROUTE);
        }
    }

    @RequestMapping(value = "/addLaw", method = RequestMethod.POST)
    public ModelAndView addLaw(@RequestParam(value = "uploadFile") MultipartFile[] files, HttpServletRequest request) {
        try {
            User user = CommonUser.getUser();
            if (user.getTid() != null) {
                KitFileUtil kitFileUtil = new KitFileUtil();
                Map<String, Object> map = new HashMap<>();
                String path = null;
                Law law = new Law();
                law.setTid(UUID.randomUUID().toString());
                law.setName(request.getParameter("name"));
                map = kitFileUtil.uploadFiles(files, "files", "law", request);
                path = map.get("path").toString();
                if (!path.equals("")) {
                    law.setFiles(path);
                }
                law.setCreateby(user.getTid());
                law.setCreatetime(new Date());
                law.setState("0");
                lawService.save(law);
                logService.getAddLog("法律法规与政策", "法律法规与政策", "新增记录" + law.getName());
            }
            return json(true);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_ADD);
        }
    }

    @RequestMapping(value = "/updateLaw", method = RequestMethod.POST)
    public ModelAndView updateLaw(@RequestParam(value = "uploadFile") MultipartFile[] files, HttpServletRequest request) {
        try {
            User user = CommonUser.getUser();
            if (user.getTid() != null) {
                KitFileUtil kitFileUtil = new KitFileUtil();
                Map<String, Object> map = new HashMap<>();
                String path = null;
                Law law = lawService.findByTid(request.getParameter("tid"));
                String filepath = request.getParameter("filepath");
                law.setName(request.getParameter("name"));
                String oldfiles = request.getParameter("oldfiles");
                map = kitFileUtil.uploadFiles(files, "files", "law", request);
                path = map.get("path").toString();
                if (!path.equals("")) {
                    //kitFileUtil.deletefiles(dossier.getFiles(),request);
                    if (!"".equals(oldfiles)) {
                        oldfiles = oldfiles + "," + path;
                    } else {
                        oldfiles = path;
                    }
                }
                law.setFiles(oldfiles);
                lawService.update(law);
                logService.getAddLog("法律法规与政策", "法律法规与政策", "修改记录" + law.getName());
            }
            return json(true);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_UPDATE);
        }
    }

    @RequestMapping(value = "/delLaw", method = RequestMethod.POST)
    public ModelAndView delLaw(HttpServletRequest request) {
        try {
            List<String> list = lawService.getSearchLawListByRequest(request);
            if (!list.isEmpty()) {
                List<Law> lawList = lawService.findPagingByListTid(list, null, null);
                for (Law law : lawList) {
                    law.setState("-1");
                    lawService.update(law);
                    logService.getAddLog("法律法规与政策", "法律法规与政策", "删除记录" + law.getName());
                }
            }
            return json(true);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_DEL);
        }
    }

    @RequestMapping(value = "/getLawByTid", method = RequestMethod.GET)
    public ModelAndView getLawByTid(HttpServletRequest request) {
        try {
            Law law = lawService.findByTid(request.getParameter("tid"));
            logService.getAddLog("法律法规与政策", "法律法规与政策", "查看" + law.getName() + "详情");
            return json(law);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_SYSTEM_ROUTE);
        }
    }

    //档案管理
    @RequestMapping(value = "/getDossierList", method = RequestMethod.GET)
    public ModelAndView getDossierList(HttpServletRequest request) {
        try {
            JSONObject jsonObject = new JSONObject();
            List<String> list = dossierService.getSearchDossierListByRequest(request);
            int pageSize = Integer.parseInt(request.getParameter("limit"));
            int pages = Integer.parseInt(request.getParameter("page"));
            Integer pageIndex = (pages - 1) * pageSize;
            if (list.isEmpty()) {
                jsonObject.put("data", false);
                jsonObject.put("count", 0);
                jsonObject.put("msg", "");
            } else {
                List<Dossier> dossierList = dossierService.findPagingByListTid(list, pageIndex, pageSize);
                if (!dossierList.isEmpty()) {
                    for (Dossier dossier : dossierList) {
                        User user = userService.findByTid(dossier.getInsertuser());
                        if (user != null) {
                            dossier.setInsertuser(user.getName());
                        }
                    }
                }
                jsonObject.put("data", dossierList);
                jsonObject.put("count", list.size());
                jsonObject.put("msg", "");
            }
            jsonObject.put("code", 0);
            logService.getAddLog("档案管理", "历史档案管理", "查询信息");
            return json(jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_SYSTEM_ROUTE);
        }
    }

    @RequestMapping(value = "/addDossier", method = RequestMethod.POST)
    public ModelAndView addDossier(@RequestParam(value = "uploadFile") MultipartFile[] files,
                                   HttpServletRequest request) {
        try {
            User user = CommonUser.getUser();
            if (user.getTid() != null) {
                KitFileUtil kitFileUtil = new KitFileUtil();
                Map<String, Object> map = new HashMap<>();
                String path = null;
                Dossier dossier = new Dossier();
                dossier.setTid(UUID.randomUUID().toString());
                dossier.setName(request.getParameter("name"));
                dossier.setKeyword(request.getParameter("keyword"));
                map = kitFileUtil.uploadFiles(files, "files", "dossier", request);
                path = map.get("path").toString();
                if (!path.equals("")) {
                    dossier.setFiles(path);
                }
                dossier.setCheck(request.getParameter("check"));
                dossier.setInsertuser(user.getTid());
                dossier.setModifyuser(user.getTid());
                dossier.setInserttime(new Date());
                dossier.setModifytime(new Date());
                dossier.setState("0");
                dossierService.save(dossier);
                logService.getAddLog("档案管理", "历史档案管理", "新增记录" + dossier.getName());
            }
            return json(true);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_ADD);
        }
    }

    @RequestMapping(value = "/getDossierByTid", method = RequestMethod.GET)
    public ModelAndView getDossierByTid(HttpServletRequest request) {
        try {
            Dossier dossier = dossierService.findByTid(request.getParameter("tid"));
            logService.getAddLog("档案管理", "历史档案管理", "查看" + dossier.getName() + "详情");
            return json(dossier);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_SYSTEM_ROUTE);
        }
    }

    @RequestMapping(value = "/updateDossier", method = RequestMethod.POST)
    public ModelAndView updateDossier(@RequestParam(value = "uploadFile") MultipartFile[] files,
                                      HttpServletRequest request) {
        try {
            KitFileUtil kitFileUtil = new KitFileUtil();
            Map<String, Object> map = new HashMap<>();
            String path = null;
//            String filepath = request.getParameter("filepath");
            User user = CommonUser.getUser();
            Dossier dossier = dossierService.findByTid(request.getParameter("tid"));
            dossier.setName(request.getParameter("name"));
            dossier.setKeyword(request.getParameter("keyword"));
            String oldfiles = request.getParameter("oldfiles");
            map = kitFileUtil.uploadFiles(files, "files", "dossier", request);
            path = map.get("path").toString();
            if (!path.equals("")) {
                if (!"".equals(oldfiles)) {
                    oldfiles = oldfiles + "," + path;
                } else {
                    oldfiles = path;
                }
            }
            dossier.setFiles(oldfiles);
            dossier.setCheck(request.getParameter("check"));
            if (user.getTid() != null) {
                dossier.setModifyuser(user.getTid());
            }
            dossier.setModifytime(new Date());
            dossierService.update(dossier);
            logService.getAddLog("档案管理", "历史档案管理", "修改记录" + dossier.getName());
            return json(true);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_UPDATE);
        }
    }

    @RequestMapping(value = "/delDossier", method = RequestMethod.POST)
    public ModelAndView delDossier(HttpServletRequest request) {
        try {
            List<String> list = dossierService.getSearchDossierListByRequest(request);
            if (!list.isEmpty()) {
                List<Dossier> dossierList = dossierService.findPagingByListTid(list, null, null);
                for (Dossier dossier : dossierList) {
                    dossier.setState("-1");
                    dossierService.update(dossier);
                    logService.getAddLog("档案管理", "历史档案管理", "删除记录" + dossier.getName());
                }
            }
            return json(true);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_DEL);
        }
    }

    @RequestMapping(value = "/getFilesListByTid", method = RequestMethod.GET)
    public ModelAndView getFilesListByTid(HttpServletRequest request) {
        try {
            JSONObject jsonObject = new JSONObject();
            String type = request.getParameter("type");
            String filelist = "", tid = request.getParameter("tid");
            String date = "", usertid = "";
            switch (type) {
                case "dossier":
                    Dossier dossier = dossierService.findByTid(tid);
                    if (dossier != null) {
                        filelist = dossier.getFiles();
                        date = dossier.getInserttimestring();
                        usertid = dossier.getInsertuser();
                    }
                    break;
                case "law":
                    Law law = lawService.findByTid(tid);
                    if (law != null) {
                        filelist = law.getFiles();
                        date = law.getCreatetimestring();
                        usertid = law.getCreateby();
                    }
                    break;
                case "shuizhi":
                    ShuiZhi shuiZhi = (ShuiZhi) peasantService.findBaseByTid(tid, "shuizhi");
                    if (shuiZhi != null) {
                        filelist = shuiZhi.getDocument();
                        date = shuiZhi.getInserttimestring();
                        usertid = shuiZhi.getInsertuser();
                    }
                    break;
                case "maintain":
                    MaintainRecord maintainRecord = maintainRecordService.findByTid(tid);
                    if (maintainRecord != null) {
                        filelist = maintainRecord.getMaintainproject();
                        date = maintainRecord.getMaintaindatestring();
                        usertid = maintainRecord.getMaintainuser();
                    }
                    break;
                default:
                    break;
            }
            if (filelist != null && !"".equals(filelist)) {
                List<JSONObject> jsonObjectList = lawService.getFilesList(filelist, request, date, usertid);
                jsonObject.put("data", jsonObjectList);
                jsonObject.put("count", jsonObjectList.size());
                jsonObject.put("msg", "");
            } else {
                jsonObject.put("data", false);
                jsonObject.put("count", 0);
                jsonObject.put("msg", "");
            }
            jsonObject.put("code", 0);
            return json(jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_SYSTEM_ROUTE);
        }
    }

    //    @RequestMapping(value = "/delDossierFile",method = RequestMethod.POST)
//    public ModelAndView delDossierFile(HttpServletRequest request){
//        try {
//            Dossier dossier = dossierService.findByTid(request.getParameter("tid"));
//            String path = request.getParameter("filepath");
//            if(dossier != null && dossier.getFiles() != null){
//                //kitFileUtil.deletefiles(filepath,request);
//                String [] file = dossier.getFiles().split(",");
//                List<String> stringList = Arrays.asList(file);
//                List<String> list = new ArrayList<>(stringList);
//                list.remove(filepath);
//                dossier.setFiles(list.toString());
//            }
//            return json(true);
//        }catch (Exception e) {
//            e.printStackTrace();
//            throw new BusinessException(ErrorCode.ERROR_DEL);
//        }
//    }
    @RequestMapping(value = "/downloadFile", method = RequestMethod.GET)
    public void downloadFile(HttpServletRequest request, HttpServletResponse response) {
        try {
            String filepath = request.getParameter("filepath");
            String name = filepath.substring(filepath.lastIndexOf("/") + 1, filepath.lastIndexOf("."));
            KitFileUtil kitFileUtil = new KitFileUtil();
            List<String> list = new ArrayList<>();
            list.add(filepath);
            kitFileUtil.downloadFile(list, name, request, response);
            logService.getAddLog("档案管理", "历史档案管理", "下载文件" + name);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_SYSTEM_ROUTE);
        }
    }

    //异常信息历史查询
    @RequestMapping(value = "/getAlertList", method = RequestMethod.GET)
    public ModelAndView getAlertList(HttpServletRequest request) {
        try {
            JSONObject jsonObject = new JSONObject();
            List<String> list = alertService.getSearchAlertListByRequest(request);
            int pageSize = Integer.parseInt(request.getParameter("limit"));
            int pages = Integer.parseInt(request.getParameter("page"));
            Integer pageIndex = (pages - 1) * pageSize;
            if (list.isEmpty()) {
                jsonObject.put("data", false);
                jsonObject.put("count", 0);
                jsonObject.put("msg", "");
            } else {
                List<Alert> alertList = alertService.findPagingByListTid(list, pageIndex, pageSize);
                jsonObject.put("data", alertList);
                jsonObject.put("count", list.size());
                jsonObject.put("msg", "");
            }
            jsonObject.put("code", 0);
            logService.getAddLog("信息管理", "异常信息历史管理", "查询信息");
            return json(jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_SYSTEM_ROUTE);
        }
    }

    @RequestMapping(value = "/getAllAlertNo")
    public ModelAndView getAlertNo(HttpServletRequest request) {
        List<Alert> list = alertMapper.selectAllAlert();
        return json(list);
    }

    @RequestMapping(value = "/getAlertByTid", method = RequestMethod.GET)
    public ModelAndView getAlertByTid(HttpServletRequest request) {
        try {
            Alert alert = alertService.findByTid(request.getParameter("tid"));
            logService.getAddLog("信息管理", "异常信息历史管理", "查看" + alert.getReason() + "详情");
            return json(alert);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.NULL_OBJ);
        }
    }

    @RequestMapping(value = "/changeAlert", method = RequestMethod.POST)
    public ModelAndView updateAlert(HttpServletRequest request) {
        try {
            Alert alert = alertService.findByTid(request.getParameter("tid"));
            alert.setState(request.getParameter("state"));
            alertService.update(alert);
            logService.getAddLog("信息管理", "异常信息历史管理", "修改记录" + alert.getReason());
            return json(true);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_UPDATE);
        }
    }

    @RequestMapping(value = "/delAlert", method = RequestMethod.POST)
    public ModelAndView delAlert(HttpServletRequest request) {
        try {
            List<String> list = alertService.getSearchAlertListByRequest(request);
            if (!list.isEmpty()) {
                List<Alert> alertList = alertService.findPagingByListTid(list, null, null);
                for (Alert alert : alertList) {
                    alert.setState("-1");
                    alertService.update(alert);
                    logService.getAddLog("信息管理", "异常信息历史管理", "删除记录" + alert.getReason());
                }
            }
            return json(true);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_DEL);
        }
    }

    @RequestMapping(value = "/getAlertListByClassify", method = RequestMethod.GET)
    public ModelAndView getAlertListByClassify(HttpServletRequest request) {
        try {
            int pageSize = Integer.parseInt(request.getParameter("limit"));
            int pages = Integer.parseInt(request.getParameter("page"));
            Integer pageIndex = (pages - 1) * pageSize;
            JSONObject jsonObject = new JSONObject();
            List<Alert> alerts = alertService.getClassifyByRequest(request, null, null);
            List<Alert> alertList = alertService.getClassifyByRequest(request, pageIndex, pageSize);
            if (alertList.isEmpty()) {
                jsonObject.put("data", false);
                jsonObject.put("count", 0);
                jsonObject.put("msg", "");
            } else {
                jsonObject.put("data", alertList);
                jsonObject.put("count", alerts.size());
                jsonObject.put("msg", "");
            }
            jsonObject.put("code", 0);
            logService.getAddLog("信息管理", "异常原因类型汇总", "查询信息");
            return json(jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_SYSTEM_ROUTE);
        }
    }

    @RequestMapping(value = "/ExportClassifyExcel", method = RequestMethod.GET)
    public void ExportClassifyExcel(HttpServletRequest request, HttpServletResponse response) {
        try {
            String type = request.getParameter("type");
            List<Alert> alertList = alertService.getClassifyByRequest(request, null, null);
            //导出excel
            response.setContentType("APPLICATION/OCTET-STREAM");
            response.setContentType("application/x-msdownload;charset=utf-8");
            response.setContentType("application/vnd.ms-excel;charset=utf-8");
            response.setHeader("Content-Disposition",
                    "attachment;filename=" + new String((type + ".xls").getBytes(), "ISO_8859_1"));
            OutputStream out = response.getOutputStream();
            alertService.ExportClassifyExcel(out, alertList, type);
            out.flush();
            out.close();
            logService.getAddLog("信息管理", "异常信息历史管理", "导出记录");
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_SYSTEM_ROUTE);
        }
    }

    @RequestMapping(value = "/getAlerts", method = RequestMethod.GET)
    public ModelAndView getAlerts() {
        try {
            JSONObject jsonObject = new JSONObject();
            JSONObject result = new JSONObject();
            Date date = new Timestamp(System.currentTimeMillis());
            List<String> list = new ArrayList<>();
            Calendar calendar = Calendar.getInstance();
            Alert alert = new Alert();
            alert.setState("0");//只查询未处理的异常
            //异常总数
            alert.setEndtime(date);
            list = alertService.getSearchAlertList(null, alert);
            jsonObject.put("sum", list.size());
            //本月异常
            calendar.set(Calendar.DAY_OF_MONTH, 1);//本月第一天
            alert.setStarttime(calendar.getTime());
            calendar.set(Calendar.DATE, 1);
            calendar.roll(Calendar.DATE, -1);
            alert.setEndtime(calendar.getTime());//本月最后一天
            list = alertService.getSearchAlertList(null, alert);
            jsonObject.put("monthsum", list.size());
            //设备正常运行总数
            int normal = 0, abnormal = 0, sumofvideo = 0;
            List<Lined> linedList = linedMapper.getAll();
            for (Lined lined : linedList) {
                if (lined != null) {
                    if ("0".equals(lined.getState())) {
                        normal++;
                    } else {
                        abnormal++;
                    }
                    if (lined.getVideoUrl() != null && !"".equals(lined.getVideoUrl())) {
                        sumofvideo++;
                    }
                }
            }
            jsonObject.put("normal", normal);
            jsonObject.put("abnormal", abnormal);
            jsonObject.put("sumofvideo", sumofvideo);
            result.put("data", jsonObject);
            result.put("msg", "");
            result.put("count", 1);
            result.put("code", 0);
            //设备非正常运行总数
            return json(result);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_SYSTEM_ROUTE);
        }
    }

    //获取所有项目
    @RequestMapping(value = "/getAllPro", method = RequestMethod.GET)
    public ModelAndView getAllPro() {
        List<ProjectTable> list = projectTableMapper.seleAll();
        Map map = new HashMap();
        map.put("data", list);
        return json(map);
    }

    @RequestMapping(value = "/exportVillage", method = RequestMethod.GET)
    public ModelAndView exportVillage() {
        List<Xzzd> zhens = xzzdServcie.selectVyPid(-1);
        for (Xzzd xzzd : zhens) {
            String zhenName = xzzd.getTitle();
            List<Xzzd> cwhs = xzzdServcie.selectVyPid(xzzd.getId());
            for (Xzzd xzzd1 : cwhs) {
                String cwhName = xzzd1.getTitle();
                List<Xzzd> cuns = xzzdServcie.selectVyPid(xzzd1.getId());
                for (Xzzd xzzd2 : cuns) {
                    String cunName = xzzd2.getTitle();
                    Village village = new Village();
                    village.setTid(UUID.randomUUID().toString());
                    village.setHushu(0);
                    ;
                    village.setZhen(zhenName);
                    village.setCunweihui(cwhName);
                    village.setName(cunName);
                    village.setCreatetime(new Date());
                    villageMapper.insertSelective(village);
                }
            }
        }
        return json(true);
    }

    //获取所有自然村
    @RequestMapping(value = "/seleAllZrc", method = RequestMethod.GET)
    public ModelAndView seleAllZrc() {
        List<Xzzd> xzzdList = xzzdServcie.selectAll();
        List<Xzzd> zrcList = new ArrayList<>();
        for (Xzzd xzzd : xzzdList) {
//          if(xzzd.getPid()!= -1){
//              Xzzd xzzd1 = xzzdServcie.selectById(xzzd.getPid());
//              if(xzzd1.getPid() != -1){
//                  zrcList.add(xzzd);
//              }
//          }

            if (xzzd.getPid() != -1) {
                if (!xzzd.getTitle().endsWith("村委会")) {
                    zrcList.add(xzzd);
                }
            }
        }
        Map map = new HashMap();
        map.put("zrcList", zrcList);
        return json(map);
    }

    //设备信息
    @RequestMapping(value = "/getListLined", method = RequestMethod.GET)
    public ModelAndView getListLined(HttpServletRequest request, HttpSession httpSession) {
        try {
            JSONObject jsonObject = new JSONObject();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            int total = 0;
            String page = request.getParameter("page");
            String limit = request.getParameter("limit");
            List<String> list = peasantService.getListBaseTidByRequest(request, "lined");
            Integer limits = Integer.valueOf(limit);
            Integer pages = Integer.valueOf(page);
            Integer pageIndex = (pages - 1) * limits;
            Integer pageSize = Integer.valueOf(limit);
            List chemicalApplications = new ArrayList<>();
            if (list.size() == 0) {
                jsonObject.put("data", false);
                jsonObject.put("count", 0);
                jsonObject.put("msg", "");
            } else {
                total = list.size();
                chemicalApplications = peasantService.findPagingByListTid(list, pageIndex, pageSize, "lined");
                Timestamp defaultTime = new Timestamp(System.currentTimeMillis());

                for (Object befour : chemicalApplications) {
                    Lined one = (Lined) befour;
                    if (one.getChanshuibengchangetime() == null) {
                        one.setChanshuibengchangetimeString("");
                        one.setChanshuibengchangetime(defaultTime);
                    } else {
                        one.setChanshuibengchangetimeString(sdf.format(one.getChanshuibengchangetime()));
                    }
                    if (one.getFanxibengchangetime() == null) {
                        one.setFanxibengchangetimeString("");
                        one.setFanxibengchangetime(defaultTime);
                    } else {
                        one.setFanxibengchangetimeString(sdf.format(one.getFanxibengchangetime()));
                    }
                    if (one.getJiaobanjichangetime() == null) {
                        one.setJiaobanjichangetimeString("");
                        one.setJiaobanjichangetime(defaultTime);
                    } else {
                        one.setJiaobanjichangetimeString(sdf.format(one.getJiaobanjichangetime()));
                    }
                    if (one.getGufengji1changetime() == null) {
                        one.setGufengji1changetimeString("");
                        one.setGufengji1changetime(defaultTime);
                    } else {
                        one.setGufengji1changetimeString(sdf.format(one.getGufengji1changetime()));
                    }

                    if (one.getGufengji2changetime() == null) {
                        one.setGufengji2changetimeString("");
                        one.setGufengji2changetime(defaultTime);
                    } else {
                        one.setGufengji2changetimeString(sdf.format(one.getGufengji2changetime()));
                    }
                    if (one.getJinshuibengchangetime() == null) {
                        one.setJinshuibengchangetimeString("");
                        one.setJinshuibengchangetime(defaultTime);
                    } else {
                        one.setJinshuibengchangetimeString(sdf.format(one.getJinshuibengchangetime()));
                    }
                    if (one.getHuiliubengchangetime() == null) {
                        one.setHuiliubengchangetimeString("");
                        one.setHuiliubengchangetime(defaultTime);
                    } else {
                        one.setHuiliubengchangetimeString(sdf.format(one.getHuiliubengchangetime()));
                    }
                    if (one.getCreateTime() == null) {
                        one.setCreateTime(defaultTime);
                    }
                }

                jsonObject.put("data", chemicalApplications);
                jsonObject.put("count", total);
                jsonObject.put("msg", "");
            }
            jsonObject.put("code", 0);
            logService.getAddLog("基本信息管理", "设备管理", "查询信息");
            return json(jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_SYSTEM_ROUTE);
        }
    }

    @RequestMapping(value = "/getListDdLined", method = RequestMethod.GET)
    public ModelAndView getListDdLined(HttpServletRequest request) {
        JSONObject jsonObject = new JSONObject();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String search = request.getParameter("key");
        int total = 0;
        String page = request.getParameter("page");
        String limit = request.getParameter("limit");
        List<String> list = ddlinedMapper.selectListTidByKey(search);
        Integer limits = Integer.valueOf(limit);
        Integer pages = Integer.valueOf(page);
        Integer pageIndex = (pages - 1) * limits;
        Integer pageSize = Integer.valueOf(limit);
        List chemicalApplications = new ArrayList<>();
        if (list.size() == 0) {
            jsonObject.put("data", false);
            jsonObject.put("count", 0);
            jsonObject.put("msg", "");
        } else {
            total = list.size();
            chemicalApplications = ddlinedMapper.findPagingByListTid(list, pageIndex, pageSize);
            Timestamp defaultTime = new Timestamp(System.currentTimeMillis());

            jsonObject.put("data", chemicalApplications);
            jsonObject.put("count", total);
            jsonObject.put("msg", "");
        }
        jsonObject.put("code", 0);
        logService.getAddLog("基本信息管理", "设备管理", "查询信息");
        return json(jsonObject);
    }

    @RequestMapping(value = "/addLined", method = RequestMethod.POST)
    public ModelAndView addLined(HttpServletRequest request, HttpSession httpSession) {
        try {
//            User user=(User)httpSession.getAttribute("userInfo");

            String tid = UUID.randomUUID().toString();
            String name = request.getParameter("name");
            String dunwei = request.getParameter("dunwei");
            String videoTid = request.getParameter("videoTid");
            String videoUrl = request.getParameter("videoUrl");
            String jingdu = request.getParameter("jingdu");
            if (jingdu != null) {
                jingdu = Dms2D(jingdu);
            }
            String weidu = request.getParameter("weidu");
            if (weidu != null) {
                weidu = Dms2D(weidu);
            }
            String zhen = request.getParameter("zhen");
            String cun = request.getParameter("cun");
            String xiang = request.getParameter("xiang");
            String ssbm = request.getParameter("ssbm");
            String yjrhs = request.getParameter("yjrhs");
            String yijrhs = request.getParameter("yijrhs");
            String ysyrs = request.getParameter("ysyrs");
            String yjsyrs = request.getParameter("yjsyrs");
            String dycjk = request.getParameter("dycjk");
            String zgl = request.getParameter("zgl");
            String csbz = request.getParameter("csbz");
            String clgy = request.getParameter("clgy");
            String sszt = request.getParameter("sszt");
            String wscljsdw = request.getParameter("wscljsdw");
            String wsclsjdw = request.getParameter("wsclsjdw");
            String wsclsgdw = request.getParameter("wsclsgdw");
            String wscljldw = request.getParameter("wscljldw");
            String zxjc = request.getParameter("zxjc");
            String gwcz = request.getParameter("gwcz");
            String zgwgj = request.getParameter("zgwgj");
            String gwc = request.getParameter("gwc");
            String jsrqString = request.getParameter("jsrqString");
            String ywrqString = request.getParameter("ywrqString");
            String jgrqString = request.getParameter("jgrqString");
            String cjdydh = request.getParameter("cjdydh");
            String cjdy = request.getParameter("cjdy");
            String zjdy = request.getParameter("zjdy");
            String zjdydh = request.getParameter("zjdydh");
            String qjdy = request.getParameter("qjdy");
            String qjdydh = request.getParameter("qjdydh");
            String proId = request.getParameter("proId");
            SimpleDateFormat format = new SimpleDateFormat("yyyy-mm-dd");
            Lined peasant = new Lined();
            peasant.setTid(tid);
            peasant.setName(name);
            peasant.setJingdu(jingdu);
            peasant.setWeidu(weidu);
            peasant.setDunwei(dunwei);
            peasant.setState("0");
            peasant.setVideoUrl("-1");
            peasant.setVideotid("-1");
            if (jgrqString != null && !jgrqString.equals("")) {
                peasant.setJgrq(format.parse(jgrqString));
            }
            if (jsrqString != null && !jsrqString.equals("")) {
                peasant.setJsrq(format.parse(jsrqString));
            }
            if (ywrqString != null && !ywrqString.equals("")) {
                peasant.setYwrq(format.parse(ywrqString));
            }
            peasant.setProId(proId);
            peasant.setSsbm(ssbm);
            peasant.setYjrhs(yjrhs);
            peasant.setYijrhs(yijrhs);
            peasant.setYsyrs(ysyrs);
            peasant.setYjsyrs(yjsyrs);
            peasant.setDycjk(dycjk);
            peasant.setZgl(zgl);
            peasant.setCsbz(csbz);
            peasant.setClgy(clgy);
            peasant.setSszt(sszt);
            peasant.setWscljsdw(wscljsdw);
            peasant.setWscljldw(wscljldw);
            peasant.setWsclsgdw(wsclsgdw);
            peasant.setWsclsjdw(wsclsjdw);
            peasant.setZxjc(zxjc);
            peasant.setGwcz(gwcz);
            peasant.setZgwgj(zgwgj);
            peasant.setGwc(gwc);
            peasant.setCjdy(cjdy);
            peasant.setCjdydh(cjdydh);
            peasant.setZjdy(zjdy);
            peasant.setZjdydh(zjdydh);
            peasant.setQjdy(qjdy);
            peasant.setQjdydh(qjdydh);
            if (cun != null && !cun.equals("")) {
                peasant.setCun(cun);
                List<Xzzd> zrcs = xzzdServcie.selectByTitle(cun);
                if (zrcs.size() > 0) {
                    Xzzd cunweihui = xzzdServcie.selectById(zrcs.get(0).getPid());
                    peasant.setCunweihui(cunweihui.getTitle());
                    Xzzd zh = xzzdServcie.selectById(cunweihui.getPid());
                    peasant.setZhen(zh.getTitle());
                }
            }
            peasantService.saveBase(peasant, "lined");
            return json(true);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_ADD);
        }
    }

    @RequestMapping(value = "/addDdLined", method = RequestMethod.POST)
    public ModelAndView addDdlined(HttpServletRequest request) throws ParseException {
        String tid = UUID.randomUUID().toString();
        String name = request.getParameter("name");
        String dunwei = request.getParameter("dunwei");
        String videoTid = request.getParameter("videoTid");
        String videoUrl = request.getParameter("videoUrl");
        String jingdu = request.getParameter("jingdu");
        if (jingdu != null) {
            jingdu = Dms2D(jingdu);
        }
        String weidu = request.getParameter("weidu");
        if (weidu != null) {
            weidu = Dms2D(weidu);
        }
        String zhen = request.getParameter("zhen");
        String cun = request.getParameter("cun");
        String xiang = request.getParameter("xiang");
        String ssbm = request.getParameter("ssbm");
        String yjrhs = request.getParameter("yjrhs");
        String yijrhs = request.getParameter("yijrhs");
        String ysyrs = request.getParameter("ysyrs");
        String yjsyrs = request.getParameter("yjsyrs");
        String dycjk = request.getParameter("dycjk");
        String zgl = request.getParameter("zgl");
        String csbz = request.getParameter("csbz");
        String clgy = request.getParameter("clgy");
        String sszt = request.getParameter("sszt");
        String wscljsdw = request.getParameter("wscljsdw");
        String wsclsjdw = request.getParameter("wsclsjdw");
        String wsclsgdw = request.getParameter("wsclsgdw");
        String wscljldw = request.getParameter("wscljldw");
        String zxjc = request.getParameter("zxjc");
        String gwcz = request.getParameter("gwcz");
        String zgwgj = request.getParameter("zgwgj");
        String gwc = request.getParameter("gwc");
        String jsrqString = request.getParameter("jsrqString");
        String ywrqString = request.getParameter("ywrqString");
        String jgrqString = request.getParameter("jgrqString");
        String cjdydh = request.getParameter("cjdydh");
        String cjdy = request.getParameter("cjdy");
        String zjdy = request.getParameter("zjdy");
        String zjdydh = request.getParameter("zjdydh");
        String qjdy = request.getParameter("qjdy");
        String qjdydh = request.getParameter("qjdydh");
        String proId = request.getParameter("proId");
        SimpleDateFormat format = new SimpleDateFormat("yyyy-mm-dd");
        Ddlined peasant = new Ddlined();
        peasant.setTid(tid);
        peasant.setName(name);
        peasant.setJingdu(jingdu);
        peasant.setWeidu(weidu);
        peasant.setDunwei(dunwei);
        peasant.setState("0");
        peasant.setVideourl("-1");
        peasant.setVideotid("-1");
        if (jgrqString != null && !jgrqString.equals("")) {
            peasant.setJgrq(format.parse(jgrqString));
        }
        if (jsrqString != null && !jsrqString.equals("")) {
            peasant.setJsrq(format.parse(jsrqString));
        }
        if (ywrqString != null && !ywrqString.equals("")) {
            peasant.setYwrq(format.parse(ywrqString));
        }
        peasant.setProid(proId);
        peasant.setSsbm(ssbm);
        peasant.setYjrhs(yjrhs);
        peasant.setYijrhs(yijrhs);
        peasant.setYsyrs(ysyrs);
        peasant.setYjsyrs(yjsyrs);
        peasant.setDycjk(dycjk);
        peasant.setZgl(zgl);
        peasant.setCsbz(csbz);
        peasant.setClgy(clgy);
        peasant.setSszt(sszt);
        peasant.setWscljsdw(wscljsdw);
        peasant.setWscljldw(wscljldw);
        peasant.setWsclsgdw(wsclsgdw);
        peasant.setWsclsjdw(wsclsjdw);
        peasant.setZxjc(zxjc);
        peasant.setGwcz(gwcz);
        peasant.setZgwgj(zgwgj);
        peasant.setGwc(gwc);
        peasant.setCjdy(cjdy);
        peasant.setCjdydh(cjdydh);
        peasant.setZjdy(zjdy);
        peasant.setZjdydh(zjdydh);
        peasant.setQjdy(qjdy);
        peasant.setQjdydh(qjdydh);
        if (cun != null && !cun.equals("")) {
            peasant.setCun(cun);
            List<Xzzd> zrcs = xzzdServcie.selectByTitle(cun);
            if (zrcs.size() > 0) {
                Xzzd cunweihui = xzzdServcie.selectById(zrcs.get(0).getPid());
                peasant.setCunweihui(cunweihui.getTitle());
                Xzzd zh = xzzdServcie.selectById(cunweihui.getPid());
                peasant.setZhen(zh.getTitle());
            }
        }
        ddlinedMapper.insert(peasant);
        return json(true);

    }

    @RequestMapping(value = "/getLinedByTid", method = {RequestMethod.POST, RequestMethod.GET})
    public ModelAndView getLinedByTid(HttpServletRequest request, HttpSession httpSession) {
        try {
            String tid = request.getParameter("tid");
            Lined chemical = (Lined) peasantService.findBaseByTid(tid, "lined");
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            Timestamp defaultTime = new Timestamp(System.currentTimeMillis());
            Lined one = chemical;
            if (one.getJingdu() != null) {
                one.setJingdu(changeToDFM(Double.valueOf(one.getJingdu())));
            }
            if (one.getWeidu() != null) {
                one.setWeidu(changeToDFM(Double.valueOf(one.getWeidu())));
            }
            if (chemical.getJsrq() != null) {
                chemical.setJsrqString(format.format(chemical.getJsrq()));
            }
            if (chemical.getJgrq() != null) {
                chemical.setJgrqSring(format.format(chemical.getJgrq()));
            }
            if (chemical.getYwrq() != null) {
                chemical.setYwrqString(format.format(chemical.getYwrq()));
            }
            if (one.getChanshuibengchangetime() == null) {
                one.setChanshuibengchangetimeString("");
                one.setChanshuibengchangetime(defaultTime);
            } else {
                one.setChanshuibengchangetimeString(sdf.format(one.getChanshuibengchangetime()));
            }
            if (one.getFanxibengchangetime() == null) {
                one.setFanxibengchangetimeString("");
                one.setFanxibengchangetime(defaultTime);
            } else {
                one.setFanxibengchangetimeString(sdf.format(one.getFanxibengchangetime()));
            }
            if (one.getJiaobanjichangetime() == null) {
                one.setJiaobanjichangetimeString("");
                one.setJiaobanjichangetime(defaultTime);
            } else {
                one.setJiaobanjichangetimeString(sdf.format(one.getJiaobanjichangetime()));
            }
            if (one.getGufengji1changetime() == null) {
                one.setGufengji1changetimeString("");
                one.setGufengji1changetime(defaultTime);
            } else {
                one.setGufengji1changetimeString(sdf.format(one.getGufengji1changetime()));
            }

            if (one.getGufengji2changetime() == null) {
                one.setGufengji2changetimeString("");
                one.setGufengji2changetime(defaultTime);
            } else {
                one.setGufengji2changetimeString(sdf.format(one.getGufengji2changetime()));
            }
            if (one.getJinshuibengchangetime() == null) {
                one.setJinshuibengchangetimeString("");
                one.setJinshuibengchangetime(defaultTime);
            } else {
                one.setJinshuibengchangetimeString(sdf.format(one.getJinshuibengchangetime()));
            }
            if (one.getHuiliubengchangetime() == null) {
                one.setHuiliubengchangetimeString("");
                one.setHuiliubengchangetime(defaultTime);
            } else {
                one.setHuiliubengchangetimeString(sdf.format(one.getHuiliubengchangetime()));
            }
            if (one.getCreateTime() == null) {
                one.setCreateTime(defaultTime);
            }
            logService.getAddLog("基本信息管理", "设备管理", "查看" + one.getNumber() + "详情");
            return json(chemical);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_SYSTEM_ROUTE);
        }
    }

    @RequestMapping(value = "getDdLinedByTid", method = {RequestMethod.POST, RequestMethod.GET})
    public ModelAndView getDdLinedByTid(HttpServletRequest request) {
        String tid = request.getParameter("tid");
//        Lined chemical = (Lined) peasantService.findBaseByTid(tid, "lined");
        Ddlined chemical = ddlinedMapper.selectByPrimaryKey(tid);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Timestamp defaultTime = new Timestamp(System.currentTimeMillis());
        Ddlined one = chemical;
        if (one.getJingdu() != null) {
            one.setJingdu(changeToDFM(Double.valueOf(one.getJingdu())));
        }
        if (one.getWeidu() != null) {
            one.setWeidu(changeToDFM(Double.valueOf(one.getWeidu())));
        }
        if (chemical.getJsrq() != null) {
            chemical.setJsrqString(format.format(chemical.getJsrq()));
        }
        if (chemical.getJgrq() != null) {
            chemical.setJgrqString(format.format(chemical.getJgrq()));
        }
        if (chemical.getYwrq() != null) {
            chemical.setYwrqString(format.format(chemical.getYwrq()));
        }
        logService.getAddLog("基本信息管理", "设备管理", "查看" + one.getNumber() + "详情");
        return json(chemical);
    }

    @RequestMapping(value = "/updateLined", method = RequestMethod.POST)
    public ModelAndView updateLined(HttpServletRequest request) {
        try {
//            User user=(User)httpSession.getAttribute("userInfo");

            String tid = request.getParameter("tid");
            String name = request.getParameter("name");
            String dunwei = request.getParameter("dunwei");
            String videoTid = request.getParameter("videoTid");
            String videoUrl = request.getParameter("videoUrl");
            String jingdu = request.getParameter("jingdu");
            String weidu = request.getParameter("weidu");
            String zhen = request.getParameter("zhen");
            String cun = request.getParameter("cun");
            String xiang = request.getParameter("xiang");
            String ssbm = request.getParameter("ssbm");
            String yjrhs = request.getParameter("yjrhs");
            String yijrhs = request.getParameter("yijrhs");
            String ysyrs = request.getParameter("ysyrs");
            String yjsyrs = request.getParameter("yjsyrs");
            String dycjk = request.getParameter("dycjk");
            String zgl = request.getParameter("zgl");
            String csbz = request.getParameter("csbz");
            String clgy = request.getParameter("clgy");
            String sszt = request.getParameter("sszt");
            String wscljsdw = request.getParameter("wscljsdw");
            String wsclsjdw = request.getParameter("wsclsjdw");
            String wsclsgdw = request.getParameter("wsclsgdw");
            String wscljldw = request.getParameter("wscljldw");
            String zxjc = request.getParameter("zxjc");
            String gwcz = request.getParameter("gwcz");
            String zgwgj = request.getParameter("zgwgj");
            String gwc = request.getParameter("gwc");
            String jsrqString = request.getParameter("jsrqString");
            String ywrqString = request.getParameter("ywrqString");
            String jgrqString = request.getParameter("jgrqString");
            String cjdydh = request.getParameter("cjdydh");
            String cjdy = request.getParameter("cjdy");
            String zjdy = request.getParameter("zjdy");
            String zjdydh = request.getParameter("zjdydh");
            String qjdy = request.getParameter("qjdy");
            String qjdydh = request.getParameter("qjdydh");
            String proId = request.getParameter("proId");
            if (jingdu != null) {
                jingdu = Dms2D(jingdu);
            }
            if (weidu != null) {
                weidu = Dms2D(weidu);
            }
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            Lined peasant = new Lined();

            peasant.setTid(tid);
            peasant.setName(name);
            peasant.setJingdu(jingdu);
            peasant.setWeidu(weidu);
            peasant.setDunwei(dunwei);
            if (jgrqString != null && !jgrqString.equals("")) {
                peasant.setJgrq(format.parse(jgrqString));
            }
            if (jsrqString != null && !jsrqString.equals("")) {
                peasant.setJsrq(format.parse(jsrqString));
            }
            if (ywrqString != null && !ywrqString.equals("")) {
                peasant.setYwrq(format.parse(ywrqString));
            }
            peasant.setProId(proId);
            peasant.setSsbm(ssbm);
            peasant.setYjrhs(yjrhs);
            peasant.setYijrhs(yijrhs);
            peasant.setYsyrs(ysyrs);
            peasant.setYjsyrs(yjsyrs);
            peasant.setDycjk(dycjk);
            peasant.setZgl(zgl);
            peasant.setCsbz(csbz);
            peasant.setClgy(clgy);
            peasant.setSszt(sszt);
            peasant.setWscljsdw(wscljsdw);
            peasant.setWscljldw(wscljldw);
            peasant.setWsclsgdw(wsclsgdw);
            peasant.setWsclsjdw(wsclsjdw);
            peasant.setZxjc(zxjc);
            peasant.setGwcz(gwcz);
            peasant.setZgwgj(zgwgj);
            peasant.setGwc(gwc);
            peasant.setCjdy(cjdy);
            peasant.setCjdydh(cjdydh);
            peasant.setZjdy(zjdy);
            peasant.setZjdydh(zjdydh);
            peasant.setQjdy(qjdy);
            peasant.setQjdydh(qjdydh);
            if (cun != null && !cun.equals("")) {
                peasant.setCun(cun);
                List<Xzzd> zrcs = xzzdServcie.selectByTitle(cun);
                if (zrcs.size() > 0) {
                    Xzzd cunweihui = xzzdServcie.selectById(zrcs.get(0).getPid());
                    peasant.setCunweihui(cunweihui.getTitle());
                    Xzzd zh = xzzdServcie.selectById(cunweihui.getPid());
                    peasant.setZhen(zh.getTitle());
                }
            }
            peasant.setTid(tid);
            linedMapper.updateByPrimaryKeySelective(peasant);
            return json(true);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_ADD);
        }
    }

    @RequestMapping(value = "/updateDdLined", method = RequestMethod.POST)
    public ModelAndView updateDdLined(HttpServletRequest request) throws ParseException {
        String tid = request.getParameter("tid");
        String name = request.getParameter("name");
        String dunwei = request.getParameter("dunwei");
        String videoTid = request.getParameter("videoTid");
        String videoUrl = request.getParameter("videoUrl");
        String jingdu = request.getParameter("jingdu");
        String weidu = request.getParameter("weidu");
        String zhen = request.getParameter("zhen");
        String cun = request.getParameter("cun");
        String xiang = request.getParameter("xiang");
        String ssbm = request.getParameter("ssbm");
        String yjrhs = request.getParameter("yjrhs");
        String yijrhs = request.getParameter("yijrhs");
        String ysyrs = request.getParameter("ysyrs");
        String yjsyrs = request.getParameter("yjsyrs");
        String dycjk = request.getParameter("dycjk");
        String zgl = request.getParameter("zgl");
        String csbz = request.getParameter("csbz");
        String clgy = request.getParameter("clgy");
        String sszt = request.getParameter("sszt");
        String wscljsdw = request.getParameter("wscljsdw");
        String wsclsjdw = request.getParameter("wsclsjdw");
        String wsclsgdw = request.getParameter("wsclsgdw");
        String wscljldw = request.getParameter("wscljldw");
        String zxjc = request.getParameter("zxjc");
        String gwcz = request.getParameter("gwcz");
        String zgwgj = request.getParameter("zgwgj");
        String gwc = request.getParameter("gwc");
        String jsrqString = request.getParameter("jsrqString");
        String ywrqString = request.getParameter("ywrqString");
        String jgrqString = request.getParameter("jgrqString");
        String cjdydh = request.getParameter("cjdydh");
        String cjdy = request.getParameter("cjdy");
        String zjdy = request.getParameter("zjdy");
        String zjdydh = request.getParameter("zjdydh");
        String qjdy = request.getParameter("qjdy");
        String qjdydh = request.getParameter("qjdydh");
        String proId = request.getParameter("proId");
        if (jingdu != null) {
            jingdu = Dms2D(jingdu);
        }
        if (weidu != null) {
            weidu = Dms2D(weidu);
        }
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Ddlined peasant = new Ddlined();

        peasant.setTid(tid);
        peasant.setName(name);
        peasant.setJingdu(jingdu);
        peasant.setWeidu(weidu);
        peasant.setDunwei(dunwei);
        if (jgrqString != null && !jgrqString.equals("")) {
            peasant.setJgrq(format.parse(jgrqString));
        }
        if (jsrqString != null && !jsrqString.equals("")) {
            peasant.setJsrq(format.parse(jsrqString));
        }
        if (ywrqString != null && !ywrqString.equals("")) {
            peasant.setYwrq(format.parse(ywrqString));
        }
        peasant.setProid(proId);
        peasant.setSsbm(ssbm);
        peasant.setYjrhs(yjrhs);
        peasant.setYijrhs(yijrhs);
        peasant.setYsyrs(ysyrs);
        peasant.setYjsyrs(yjsyrs);
        peasant.setDycjk(dycjk);
        peasant.setZgl(zgl);
        peasant.setCsbz(csbz);
        peasant.setClgy(clgy);
        peasant.setSszt(sszt);
        peasant.setWscljsdw(wscljsdw);
        peasant.setWscljldw(wscljldw);
        peasant.setWsclsgdw(wsclsgdw);
        peasant.setWsclsjdw(wsclsjdw);
        peasant.setZxjc(zxjc);
        peasant.setGwcz(gwcz);
        peasant.setZgwgj(zgwgj);
        peasant.setGwc(gwc);
        peasant.setCjdy(cjdy);
        peasant.setCjdydh(cjdydh);
        peasant.setZjdy(zjdy);
        peasant.setZjdydh(zjdydh);
        peasant.setQjdy(qjdy);
        peasant.setQjdydh(qjdydh);
        if (cun != null && !cun.equals("")) {
            peasant.setCun(cun);
            List<Xzzd> zrcs = xzzdServcie.selectByTitle(cun);
            if (zrcs.size() > 0) {
                Xzzd cunweihui = xzzdServcie.selectById(zrcs.get(0).getPid());
                peasant.setCunweihui(cunweihui.getTitle());
                Xzzd zh = xzzdServcie.selectById(cunweihui.getPid());
                peasant.setZhen(zh.getTitle());
            }
        }
        peasant.setTid(tid);
        ddlinedMapper.updateByPrimaryKeySelective(peasant);
        return json(true);
    }


    @RequestMapping(value = "/delLined", method = RequestMethod.POST)
    public ModelAndView delLined(HttpServletRequest request) {
        try {
            String tid = request.getParameter("tid");
            Lined lined = (Lined) peasantService.findBaseByTid(tid, "lined");
//            lined.setState("-1");
//            peasantService.updateBase(lined, "lined");
            peasantService.deleteBase(tid,"lined");
            logService.getAddLog("基本信息维护", "设备管理", "删除记录" + lined.getNumber());
            if (lined.getReason() != null && !"".equals(lined.getReason())) {
                LinedState linedState = linedStateMapper.getLinedStateByField("number", lined.getNumber().trim());
                if (linedState != null) {
                    linedState.setBinding("0");
                    //将该DTU的状态修改为未绑定
                    linedStateMapper.updateByPrimaryKeySelective(linedState);
                    logService.getAddLog("基本信息维护", "村委会名录管理", lined.getCun() + "解绑DTU");
                }
            }
            return json(true);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_DEL);
        }
    }

    @RequestMapping(value = "/delDdLined", method = RequestMethod.GET)
    public ModelAndView delDdLined(HttpServletRequest request) {
        String tid = request.getParameter("tid");
        Ddlined lined = ddlinedMapper.selectByPrimaryKey(tid);
        lined.setState("-1");
        ddlinedMapper.updateByPrimaryKeySelective(lined);
//            peasantService.deleteBase(tid,"lined");
        logService.getAddLog("基本信息维护", "设备管理", "删除记录" + lined.getNumber());
        if (lined.getReason() != null && !"".equals(lined.getReason())) {
            LinedState linedState = linedStateMapper.getLinedStateByField("number", lined.getNumber().trim());
            if (linedState != null) {
                linedState.setBinding("0");
                //将该DTU的状态修改为未绑定
                linedStateMapper.updateByPrimaryKeySelective(linedState);
                logService.getAddLog("基本信息维护", "村委会名录管理", lined.getCun() + "解绑DTU");
            }
        }
        return json(true);
    }

    @RequestMapping(value = "/getDisplayLined", method = RequestMethod.GET)
    public ModelAndView getDisplayLined() {
        try {
            DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            List<Lined> newList = new ArrayList<>();
            List<Lined> linedList = linedMapper.getAll();
            for (Lined lined : linedList) {
                if (lined.getNumber() != null && !"".equals(lined.getNumber()) || lined.getVideoUrl() != null && !"".equals(lined.getVideoUrl())) {
                    if (lined.getCreateTime() == null) {
                        lined.setCreateTime(new Date());
                    }
                    lined.setCreatetimestring(dateFormat.format(lined.getCreateTime()));
                    newList.add(lined);
                }
            }
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("data", newList);
            return json(jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_SYSTEM_ROUTE);
        }
    }

    @RequestMapping(value = "/getLineSumBi", method = RequestMethod.GET)
    public ModelAndView getLineSumBi() {
        try {
            JSONArray result = new JSONArray();
            JSONArray run = new JSONArray();
            JSONArray stop = new JSONArray();
            List<Lined> linedList = linedMapper.getAll();
            int chanshuis = 0, chanshuie = 0, fanxijis = 0, fanxijie = 0, gufengjis = 0;
            int gufengjie = 0, jiaobanjis = 0, jiaobanjie = 0, huiliubengs = 0, huiliubenge = 0;
            if (!linedList.isEmpty()) {
                for (Lined lined : linedList) {
                    if (lined != null) {
                        if (lined.getChanshuibengstrattime() != null) {
                            chanshuis += lined.getChanshuibengstrattime();
                        }
                        if (lined.getChanshuibengendtime() != null) {
                            chanshuie += lined.getChanshuibengendtime();
                        }
                        if (lined.getFanxibengstrattime() != null) {
                            fanxijis += lined.getFanxibengstrattime();
                        }

                        if (lined.getFanxibengendtime() != null) {
                            fanxijie += lined.getFanxibengendtime();
                        }
                        if (lined.getGufengjistrattime() != null) {

                            gufengjis += lined.getGufengjistrattime();
                        }
                        if (lined.getGufengjiendtime() != null) {
                            gufengjie += lined.getGufengjiendtime();
                        }
                        if (lined.getJiaobanjistrattime() != null) {
                            jiaobanjis += lined.getJiaobanjistrattime();
                        }

                        if (lined.getJiaobanjiendtime() != null) {
                            jiaobanjie += lined.getJiaobanjiendtime();
                        }

                        if (lined.getHuiliubengstarttime() != null) {
                            huiliubengs += lined.getHuiliubengstarttime();
                        }
                        if (lined.getHuiliubengendtime() != null) {
                            huiliubenge += lined.getHuiliubengendtime();
                        }

                    }
                }
            }
            run.add(chanshuis);
            run.add(fanxijis);
            run.add(gufengjis);
            run.add(jiaobanjis);
            run.add(huiliubengs);
            stop.add(chanshuie);
            stop.add(fanxijie);
            stop.add(gufengjie);
            stop.add(jiaobanjie);
            stop.add(huiliubenge);
            result.add(run);
            result.add(stop);
            return json(result);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_SYSTEM_ROUTE);
        }
    }

    @RequestMapping(value = "/getUnboundLinedState", method = RequestMethod.GET)
    public ModelAndView getUnboundLinedState() {
        try {
            JSONObject jsonObject = new JSONObject();
            List<LinedState> linedStateList = linedStateMapper.getUnboundLinedState();
            List<LinedState> list = new ArrayList<>();
            for (LinedState linedState : linedStateList) {
                if (linedState.getNumber().contains("WZSNW")) {
                    list.add(linedState);
                }
            }
            if (linedStateList.isEmpty()) {
                jsonObject.put("data", false);
            } else {
                jsonObject.put("data", list);
            }
            return json(jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_SYSTEM_ROUTE);
        }
    }

    @RequestMapping(value = "/getUnboundDdLinedState", method = RequestMethod.GET)
    public ModelAndView getUnboundDdLinedState() {
        try {
            JSONObject jsonObject = new JSONObject();
            List<LinedState> linedStateList = linedStateMapper.getUnboundLinedState();
            List<LinedState> list = new ArrayList<>();
            for (LinedState linedState : linedStateList) {
                if (linedState.getNumber().contains("DSG4RV1")) {
                    list.add(linedState);
                }
            }
            if (linedStateList.isEmpty()) {
                jsonObject.put("data", false);
            } else {
                jsonObject.put("data", list);
            }
            return json(jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_SYSTEM_ROUTE);
        }
    }

    @RequestMapping(value = "/getReportingData", method = RequestMethod.GET)
    public ModelAndView getReportingData(HttpServletRequest request) {
        try {
            JSONObject jsonObject = new JSONObject();
            String operateType = request.getParameter("operateType");
            switch (operateType) {
                case "alert":
                    jsonObject = importExcelService.getDeviceFailure();
                    break;
                case "lined":
                    jsonObject = importExcelService.getDeviceOfLined();
                    break;
                case "water":
                    jsonObject = importExcelService.getWaterQuality();
                    break;
                case "peasant":
                    jsonObject = importExcelService.getPeasantNumberOfVillage();
                    break;
                default:
                    break;
            }
            return json(jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_SYSTEM_ROUTE);
        }
    }

    @RequestMapping(value = "/importReportingExcel", method = RequestMethod.GET)
    public void importReportingExcel(HttpServletRequest request, HttpServletResponse response) {
        try {
            JSONObject jsonObject = new JSONObject();
            String operateType = request.getParameter("operateType");
            String name = "";
            String[] head = new String[0];
            switch (operateType) {
                case "alert":
                    jsonObject = importExcelService.getDeviceFailure();
                    name = "设备故障汇总表";
                    head = new String[]{"序号", "故障类型", "故障次数汇总"};
                    break;
                case "lined":
                    jsonObject = importExcelService.getDeviceOfLined();
                    name = "乡镇村委会的设备统计表";
                    head = new String[]{"序号", "乡镇", "村委会", "设备数量", "摄像头数量"};
                    break;
                case "water":
                    jsonObject = importExcelService.getWaterQuality();
                    name = "水质检测情况汇总表";
                    head = new String[]{"序号", "村名", "检测次数"};
                    break;
                case "peasant":
                    jsonObject = importExcelService.getPeasantNumberOfVillage();
                    name = "乡镇村委会登记农户统计";
                    head = new String[]{"序号", "乡镇", "村委会", "农户数量"};
                    break;
                default:
                    break;
            }
            OutputStream out = null;
            response.setContentType("APPLICATION/OCTET-STREAM");
            response.setContentType("application/x-msdownload;charset=utf-8");
            response.setContentType("application/vnd.ms-excel;charset=utf-8");
            response.setHeader("Content-Disposition",
                    "attachment;filename=" + new String((name + ".xls").getBytes(), StandardCharsets.ISO_8859_1));
            out = response.getOutputStream();
            importExcelService.importExcel(out, jsonObject, name, head);
            out.flush();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_SYSTEM_ROUTE);
        }
    }

    @RequestMapping(value = "/toGetReporting", method = RequestMethod.GET)
    public String toGetReporting(HttpServletRequest request) {
        try {
            String operateType = request.getParameter("operateType");
            switch (operateType) {
                case "alert":
                    request.setAttribute("operateType", "alert");
                    break;
                case "lined":
                    request.setAttribute("operateType", "lined");
                    break;
                case "water":
                    request.setAttribute("operateType", "water");
                    break;
                case "peasant":
                    request.setAttribute("operateType", "peasant");
                    break;
                default:
                    break;
            }
            Subject subject = SecurityUtils.getSubject();
            Session session = subject.getSession();
            session.setAttribute("user", (User) subject.getPrincipal());
            Date date = new Date();
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
            session.setAttribute("datetime", simpleDateFormat.format(date));
            session.setAttribute("year", sdf.format(date));
            return "instrument/reporting_list";
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.ERROR_SYSTEM_ROUTE);
        }
    }

    public static String Dms2D(String jwd) {
        if (jwd != null && (jwd.contains("°"))) {//如果不为空并且存在度单位
            //计算前进行数据处理
            jwd = jwd.replace("E", "").replace("N", "").replace(":", "").replace("：", "");
            double d = 0, m = 0, s = 0;
            d = Double.parseDouble(jwd.split("°")[0]);
            //不同单位的分，可扩展
            if (jwd.contains("′")) {//正常的′
                m = Double.parseDouble(jwd.split("°")[1].split("′")[0]);
            } else if (jwd.contains("'")) {//特殊的'
                m = Double.parseDouble(jwd.split("°")[1].split("'")[0]);
            }
            //不同单位的秒，可扩展
            if (jwd.contains("″")) {//正常的″
                //有时候没有分 如：112°10.25″
                s = jwd.contains("′") ? Double.parseDouble(jwd.split("′")[1].split("″")[0]) : Double.parseDouble(jwd.split("°")[1].split("″")[0]);
            } else if (jwd.contains("''")) {//特殊的''
                //有时候没有分 如：112°10.25''
                s = jwd.contains("'") ? Double.parseDouble(jwd.split("'")[1].split("''")[0]) : Double.parseDouble(jwd.split("°")[1].split("''")[0]);
            }
            jwd = String.valueOf(d + m / 60 + s / 60 / 60);//计算并转换为string
            //使用BigDecimal进行加减乘除
	/*BigDecimal bd = new BigDecimal("60");
	BigDecimal d = new BigDecimal(jwd.contains("°")?jwd.split("°")[0]:"0");
	BigDecimal m = new BigDecimal(jwd.contains("′")?jwd.split("°")[1].split("′")[0]:"0");
	BigDecimal s = new BigDecimal(jwd.contains("″")?jwd.split("′")[1].split("″")[0]:"0");
	//divide相除可能会报错（无限循环小数），要设置保留小数点
	jwd = String.valueOf(d.add(m.divide(bd,6,BigDecimal.ROUND_HALF_UP)
            .add(s.divide(bd.multiply(bd),6,BigDecimal.ROUND_HALF_UP))));*/
        }
        return jwd;
    }

    public static String changeToDFM(double du) {
        int du1 = (int) du;
        double tp = (du - du1) * 60;
        int fen = (int) tp;
        String miao = String.format("%.2f", Math.abs(((tp - fen) * 60)));
        return du1 + "°" + Math.abs(fen) + "'" + miao + "\"";
    }

    @RequestMapping(value = "/getwxssList", method = RequestMethod.GET)
    public ModelAndView getwxssList(HttpServletRequest request) {
        JSONObject jsonObject = new JSONObject();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        int total = 0;
        String page = request.getParameter("page");
        String limit = request.getParameter("limit");
        //List<String> list = new ArrayList<String>();
        String key = request.getParameter("key");
        List<String> ids = wxssMapper.selectListTidBySearch(key);
        Integer limits = Integer.valueOf(limit);
        Integer pages = Integer.valueOf(page);
        Integer pageIndex = (pages - 1) * limits;
        Integer pageSize = Integer.valueOf(limit);
        List<Wxss> list = new ArrayList<>();
        jsonObject.put("code", 0);
        if (ids.size() > 0) {
            list = wxssMapper.findPagingByListTid(ids, pageIndex, pageSize);
            for (Wxss wxss : list) {
                if (wxss.getWxrq() != null && !"".equals(wxss.getWxrq())) {
                    wxss.setWxrqSting(sdf.format(wxss.getWxrq()));
                }
            }
            jsonObject.put("data", list);
            jsonObject.put("count", ids.size());
            jsonObject.put("msg", "");
            return json(jsonObject);
        } else {
            jsonObject.put("data", list);
            jsonObject.put("count", 0);
            jsonObject.put("msg", "");
            return json(jsonObject);
        }

    }

    @RequestMapping(value = "/addwxss", method = RequestMethod.POST)
    public ModelAndView addWxss(HttpServletRequest request) throws ParseException {
        Wxss wxss = new Wxss();
        String czmc = request.getParameter("czmc");
        String ssbm = request.getParameter("ssbm");
        String wxssName = request.getParameter("wxss");
        String wxxmjnr = request.getParameter("wxxmjnr");
        String wxtj = request.getParameter("wxtj");
        String wxhzk = request.getParameter("wxhzk");
        String wxlsry = request.getParameter("wxlsry");
        String bz = request.getParameter("bz");
        String wxrqSting = request.getParameter("wxrqSting");
        if (wxrqSting != null && !"".equals(wxrqSting)) {
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            wxss.setWxrq(simpleDateFormat.parse(wxrqSting));
        }
        String id = UUID.randomUUID().toString();
        wxss.setId(id);
        wxss.setWxss(wxssName);
        wxss.setCzmc(czmc);
        wxss.setSsbm(ssbm);
        wxss.setWxxmjnr(wxxmjnr);
        wxss.setWxtj(wxtj);
        wxss.setWxlsry(wxlsry);
        wxss.setWxhzk(wxhzk);
        wxss.setBz(bz);
        wxssMapper.insertWxss(wxss);
        return json(true);
    }

    @RequestMapping(value = "/getWxssById", method = RequestMethod.GET)
    public ModelAndView getWxssById(HttpServletRequest request) {
        String id = request.getParameter("id");
        Wxss wxss = wxssMapper.selectWxssById(id);
        if (wxss.getWxrq() != null) {
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            wxss.setWxrqSting(simpleDateFormat.format(wxss.getWxrq()));
        }
        return json(wxss);
    }

    @RequestMapping(value = "/updateWxss", method = RequestMethod.POST)
    public ModelAndView updateWxss(HttpServletRequest request) throws ParseException {
        Wxss wxss = new Wxss();
        String czmc = request.getParameter("czmc");
        String ssbm = request.getParameter("ssbm");
        String wxssName = request.getParameter("wxss");
        String wxxmjnr = request.getParameter("wxxmjnr");
        String wxtj = request.getParameter("wxtj");
        String wxhzk = request.getParameter("wxhzk");
        String wxlsry = request.getParameter("wxlsry");
        String bz = request.getParameter("bz");
        String wxrqSting = request.getParameter("wxrqSting");
        if (wxrqSting != null && !"".equals(wxrqSting)) {
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            wxss.setWxrq(simpleDateFormat.parse(wxrqSting));
        }
        String id = request.getParameter("id");
        wxss.setId(id);
        wxss.setWxss(wxssName);
        wxss.setCzmc(czmc);
        wxss.setSsbm(ssbm);
        wxss.setWxxmjnr(wxxmjnr);
        wxss.setWxtj(wxtj);
        wxss.setWxlsry(wxlsry);
        wxss.setWxhzk(wxhzk);
        wxss.setBz(bz);
        wxssMapper.updateWxss(wxss);
        return json(true);
    }

    @RequestMapping(value = "/delWxssById", method = RequestMethod.POST)
    public ModelAndView delWxssById(HttpServletRequest request) {
        String id = request.getParameter("id");
        wxssMapper.deleteWxssById(id);
        return json(true);
    }

    @RequestMapping(value = "/getYhjlLsiy", method = RequestMethod.GET)
    public ModelAndView getYhjlLsiy(HttpServletRequest request) {
        JSONObject jsonObject = new JSONObject();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        int total = 0;
        String page = request.getParameter("page");
        String limit = request.getParameter("limit");
        //List<String> list = new ArrayList<String>();
        String key = request.getParameter("key");
        List<String> ids = yhjlMapper.selectListTidBySearch(key);
        Integer limits = Integer.valueOf(limit);
        Integer pages = Integer.valueOf(page);
        Integer pageIndex = (pages - 1) * limits;
        Integer pageSize = Integer.valueOf(limit);
        List<Yhjl> list = new ArrayList<>();
        jsonObject.put("code", 0);
        if (ids.size() > 0) {
            list = yhjlMapper.findPagingByListTid(ids, pageIndex, pageSize);
            for (Yhjl yhjl : list) {
                if (yhjl.getYhrq() != null && !"".equals(yhjl.getYhrq())) {
                    yhjl.setYhrqString(sdf.format(yhjl.getYhrq()));
                }
            }
            jsonObject.put("data", list);
            jsonObject.put("count", ids.size());
            jsonObject.put("msg", "");
            return json(jsonObject);
        } else {
            jsonObject.put("data", list);
            jsonObject.put("count", 0);
            jsonObject.put("msg", "");
            return json(jsonObject);
        }

    }

    @RequestMapping(value = "/addyhjl", method = RequestMethod.POST)
    public ModelAndView addyhjl(HttpServletRequest request) throws ParseException {
        Yhjl yhjl = new Yhjl();
        String czmc = request.getParameter("czmc");
        String ssbm = request.getParameter("ssbm");
        String yhss = request.getParameter("yhss");
        String yhxmjnr = request.getParameter("yhxmjnr");
        String yhhzk = request.getParameter("yhhzk");
        String yhry = request.getParameter("yhry");
        String bz = request.getParameter("bz");
        String yhrqString = request.getParameter("yhrqString");
        if (yhrqString != null && !"".equals(yhrqString)) {
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            yhjl.setYhrq(simpleDateFormat.parse(yhrqString));
        }
        String id = UUID.randomUUID().toString();
        yhjl.setCzmc(czmc);
        yhjl.setSsbm(ssbm);
        yhjl.setYhss(yhss);
        yhjl.setYhxmjnr(yhxmjnr);
        yhjl.setYhhzk(yhhzk);
        yhjl.setYhry(yhry);
        yhjl.setBz(bz);
        yhjl.setId(id);
        yhjlMapper.insertYhjl(yhjl);
        return json(true);
    }

    @RequestMapping(value = "/updateyhjl", method = RequestMethod.POST)
    public ModelAndView updateyhjl(HttpServletRequest request) throws ParseException {
        Yhjl yhjl = new Yhjl();
        String czmc = request.getParameter("czmc");
        String ssbm = request.getParameter("ssbm");
        String yhss = request.getParameter("yhss");
        String yhxmjnr = request.getParameter("yhxmjnr");
        String yhhzk = request.getParameter("yhhzk");
        String yhry = request.getParameter("yhry");
        String bz = request.getParameter("bz");
        String yhrqString = request.getParameter("yhrqString");
        if (yhrqString != null && !"".equals(yhrqString)) {
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            yhjl.setYhrq(simpleDateFormat.parse(yhrqString));
        }
        String id = request.getParameter("id");
        yhjl.setCzmc(czmc);
        yhjl.setSsbm(ssbm);
        yhjl.setYhss(yhss);
        yhjl.setYhxmjnr(yhxmjnr);
        yhjl.setYhhzk(yhhzk);
        yhjl.setYhry(yhry);
        yhjl.setBz(bz);
        yhjl.setId(id);
        yhjlMapper.updateYhjl(yhjl);
        return json(true);
    }

    @RequestMapping(value = "/getYhjlById", method = RequestMethod.GET)
    public ModelAndView getYhjlById(HttpServletRequest request) {
        String id = request.getParameter("id");
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Yhjl yhjl = yhjlMapper.selectYhjlById(id);
        if (yhjl.getYhrq() != null) {
            yhjl.setYhrqString(simpleDateFormat.format(yhjl.getYhrq()));
        }
        return json(yhjl);
    }

    @RequestMapping(value = "/delYhjlById", method = RequestMethod.POST)
    public ModelAndView delYhjlById(HttpServletRequest request) {
        String id = request.getParameter("id");
        yhjlMapper.deleteYhjlById(id);
        return json(true);
    }

    @RequestMapping(value = "/getLineByCunzi", method = RequestMethod.POST)
    public ModelAndView getLineByCunzi(HttpServletRequest request) {
        String cun = request.getParameter("cun");
        Lined lined = linedMapper.seletLineByCun(cun);
        if (lined == null) {
            return json(0);
        } else {
            return json(lined);
        }

    }

    @RequestMapping(value = "/getSzjcList", method = RequestMethod.GET)
    public ModelAndView getSzjcList(HttpServletRequest request) {
        JSONObject jsonObject = new JSONObject();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        int total = 0;
        String page = request.getParameter("page");
        String limit = request.getParameter("limit");
        //List<String> list = new ArrayList<String>();
        String key = request.getParameter("key");
        List<String> ids = szjcMapper.selectListTidBySearch(key);
        Integer limits = Integer.valueOf(limit);
        Integer pages = Integer.valueOf(page);
        Integer pageIndex = (pages - 1) * limits;
        Integer pageSize = Integer.valueOf(limit);
        List<Szjc> list = new ArrayList<>();
        jsonObject.put("code", 0);
        if (ids.size() > 0) {
            list = szjcMapper.findPagingByListTid(ids, pageIndex, pageSize);
            for (Szjc szjc : list) {
                szjc.setCreateDateString(sdf.format(szjc.getCreateDate()));
            }
            jsonObject.put("data", list);
            jsonObject.put("count", ids.size());
            jsonObject.put("msg", "");
            return json(jsonObject);
        } else {
            jsonObject.put("data", list);
            jsonObject.put("count", 0);
            jsonObject.put("msg", "");
            return json(jsonObject);
        }

    }

    @RequestMapping(value = "/addSzjc", method = RequestMethod.POST)
    public ModelAndView addSzjc(HttpServletRequest request) throws ParseException {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        String cph = request.getParameter("cph");
        String chxxyl = request.getParameter("chxxyl");
        String cad = request.getParameter("cad");
        String czd = request.getParameter("czd");
        String czl = request.getParameter("czl");
        String cxfw = request.getParameter("cxfw");
        String cfdcjqs = request.getParameter("cfdcjqs");
        String cdzwy = request.getParameter("cdzwy");
        String jph = request.getParameter("jph");
        String jhxxyl = request.getParameter("jhxxyl");
        String jad = request.getParameter("jad");
        String jzd = request.getParameter("jzd");
        String jzl = request.getParameter("jzl");
        String jxfw = request.getParameter("jxfw");
        String jfdcjqs = request.getParameter("jfdcjqs");
        String jdzwy = request.getParameter("jdzwy");
        String cun = request.getParameter("cun");
        String createDateString = request.getParameter("createDateString");
        Szjc szjc = new Szjc();
        szjc.setCph(cph);
        szjc.setChxxyl(chxxyl);
        szjc.setCad(cad);
        szjc.setCzd(czd);
        szjc.setCzl(czl);
        szjc.setCxfw(cxfw);
        szjc.setCfdcjqs(cfdcjqs);
        szjc.setCdzwy(cdzwy);
        szjc.setJph(jph);
        szjc.setJhxxyl(jhxxyl);
        szjc.setJad(jad);
        szjc.setJzd(jzd);
        szjc.setJxfw(jxfw);
        szjc.setJzl(jzl);
        szjc.setJfdcjqs(jfdcjqs);
        szjc.setJdzwy(jdzwy);
        szjc.setCun(cun);
        if (createDateString == null || "".equals(createDateString)) {
            szjc.setCreateDate(new Date());
        } else {
            Date date = format.parse(createDateString);
            szjc.setCreateDate(date);
        }
        szjc.setId(UUID.randomUUID().toString());
        szjcMapper.insertSzjc(szjc);
        return json(true);
    }

    @RequestMapping(value = "/getSzjcById", method = RequestMethod.GET)
    public ModelAndView getSzjcById(HttpServletRequest request) {
        String id = request.getParameter("id");
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Szjc szjc = szjcMapper.selectSzjcById(id);
        if (szjc.getCreateDate() != null) {
            szjc.setCreateDateString(simpleDateFormat.format(szjc.getCreateDate()));
        }
        return json(szjc);
    }

    @RequestMapping(value = "/updateSzjc", method = RequestMethod.POST)
    public ModelAndView updateSzjc(HttpServletRequest request) throws ParseException {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        String cph = request.getParameter("cph");
        String chxxyl = request.getParameter("chxxyl");
        String cad = request.getParameter("cad");
        String czd = request.getParameter("czd");
        String czl = request.getParameter("czl");
        String cxfw = request.getParameter("cxfw");
        String cfdcjqs = request.getParameter("cfdcjqs");
        String cdzwy = request.getParameter("cdzwy");
        String jph = request.getParameter("jph");
        String jhxxyl = request.getParameter("jhxxyl");
        String jad = request.getParameter("jad");
        String jzd = request.getParameter("jzd");
        String jzl = request.getParameter("jzl");
        String jxfw = request.getParameter("jxfw");
        String jfdcjqs = request.getParameter("jfdcjqs");
        String jdzwy = request.getParameter("jdzwy");
        String cun = request.getParameter("cun");
        String id = request.getParameter("id");
        String createDateString = request.getParameter("createDateString");
        Szjc szjc = new Szjc();
        szjc.setCph(cph);
        szjc.setChxxyl(chxxyl);
        szjc.setCad(cad);
        szjc.setCzd(czd);
        szjc.setCzl(czl);
        szjc.setCxfw(cxfw);
        szjc.setCfdcjqs(cfdcjqs);
        szjc.setCdzwy(cdzwy);
        szjc.setJph(jph);
        szjc.setJhxxyl(jhxxyl);
        szjc.setJad(jad);
        szjc.setJzd(jzd);
        szjc.setJxfw(jxfw);
        szjc.setJzl(jzl);
        szjc.setJfdcjqs(jfdcjqs);
        szjc.setJdzwy(jdzwy);
        szjc.setCun(cun);
        szjc.setId(id);
        if (createDateString == null || "".equals(createDateString)) {
            szjc.setCreateDate(new Date());
        } else {
            Date date = format.parse(createDateString);
            szjc.setCreateDate(date);
        }
        szjcMapper.updateSzjc(szjc);
        return json(true);
    }

    @RequestMapping(value = "/delSzjcById", method = RequestMethod.POST)
    public ModelAndView delSzjcById(HttpServletRequest request) {
        String id = request.getParameter("id");
       int i = szjcMapper.deleteSzjcById(id);
        return json(true);
    }

    @RequestMapping(value = "/getXcxjList", method = RequestMethod.GET)
    public ModelAndView getXcxjList(HttpServletRequest request) {
        JSONObject jsonObject = new JSONObject();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        int total = 0;
        String page = request.getParameter("page");
        String limit = request.getParameter("limit");
        //List<String> list = new ArrayList<String>();
        String key = request.getParameter("key");
        List<String> ids = xcxjMapper.selectListTidBySearch(key);
        Integer limits = Integer.valueOf(limit);
        Integer pages = Integer.valueOf(page);
        Integer pageIndex = (pages - 1) * limits;
        Integer pageSize = Integer.valueOf(limit);
        List<Xcxj> list = new ArrayList<>();
        jsonObject.put("code", 0);
        if (ids.size() > 0) {
            list = xcxjMapper.findPagingByListTid(ids, pageIndex, pageSize);
            for (Xcxj xcxj : list) {
                if (xcxj.getXcrq() != null) {
                    xcxj.setXcrqString(sdf.format(xcxj.getXcrq()));
                }
            }
            jsonObject.put("data", list);
            jsonObject.put("count", ids.size());
            jsonObject.put("msg", "");
            return json(jsonObject);
        } else {
            jsonObject.put("data", list);
            jsonObject.put("count", 0);
            jsonObject.put("msg", "");
            return json(jsonObject);
        }

    }

    @RequestMapping(value = "/getXcxjById", method = RequestMethod.GET)
    public ModelAndView getXcxjById(HttpServletRequest request) {
        String id = request.getParameter("id");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Xcxj xcxj = xcxjMapper.selectXcxjById(id);
        if (xcxj.getXcrq() != null) {
            xcxj.setXcrqString(sdf.format(xcxj.getXcrq()));
        }
        return json(xcxj);
    }

    @RequestMapping(value = "/delXcxjById", method = RequestMethod.POST)
    public ModelAndView delXcxjById(HttpServletRequest request) {
        String id = request.getParameter("id");
        xcxjMapper.deleteXcxjById(id);
        return json(true);
    }

    @RequestMapping(value = "/addXjxc", method = RequestMethod.POST)
    public ModelAndView addXjxc(HttpServletRequest request) throws ParseException {
        String czmc = request.getParameter("czmc");
        String ssbm = request.getParameter("ssbm");
        String xcrqString = request.getParameter("xcrqString");
        String xctq = request.getParameter("xctq");
        String xcry = request.getParameter("xcry");
        String xcrydh = request.getParameter("xcrydh");
        String clgy = request.getParameter("clgy");
        String jssl = request.getParameter("jssl");
        String cssl = request.getParameter("cssl");
        String sl = request.getParameter("sl");
        String pfkys = request.getParameter("pfkys");
        String pfkyw = request.getParameter("pfkyw");
        String gl = request.getParameter("gl");
        String kzg = request.getParameter("kzg");
        String fj = request.getParameter("fj");
        String fmj = request.getParameter("fmj");
        String tsb = request.getParameter("tsb");
        String hlb = request.getParameter("hlb");
        String llj = request.getParameter("llj");
        String gdjfm = request.getParameter("gdjfm");
        String kzf = request.getParameter("kzf");
        String ywkzxt = request.getParameter("ywkzxt");
        String gsp = request.getParameter("gsp");
        String zxjksb = request.getParameter("zxjksb");
        String qtsb = request.getParameter("qtsb");
        String jsj = request.getParameter("jsj");
        String cdc = request.getParameter("cdc");
        String yyc = request.getParameter("yyc");
        String qyc = request.getParameter("qyc");
        String hyc = request.getParameter("hyc");
        String wdt = request.getParameter("wdt");
        String rgsdmsqk = request.getParameter("rgsdmsqk");
        String rgsdsfds = request.getParameter("rgsdsfds");
        String rgsdzwszqk = request.getParameter("rgsdzwszqk");
        String rgsdqtwt = request.getParameter("rgsdqtwt");
        String ythclss = request.getParameter("ythclss");
        String csj = request.getParameter("csj");
        String cdhj = request.getParameter("cdhj");
        String zdwl = request.getParameter("zdwl");
        String gljkjjg = request.getParameter("gljkjjg");
        String qtss = request.getParameter("qtss");
        String gd = request.getParameter("gd");
        String wsj = request.getParameter("wsj");
        String tsbz = request.getParameter("tsbz");
        String jhg = request.getParameter("jhg");
        String jhj = request.getParameter("jhj");
        String hyhfc = request.getParameter("hyhfc");
        String cfqsj = request.getParameter("cfqsj");
        String dl = request.getParameter("dl");
        String qtwt = request.getParameter("qtwt");
        String glqtwt = request.getParameter("glqtwt");
        String kzgqtwt = request.getParameter("kzgqtwt");
        String fjqtwt = request.getParameter("fjqtwt");
        String fmqtwt = request.getParameter("fmqtwt");
        String tsbqtwt = request.getParameter("tsbqtwt");
        String hlbqtwt = request.getParameter("hlbqtwt");
        String lljqtwt = request.getParameter("lljqtwt");
        String gdjfmqtwt = request.getParameter("gdjfmqtwt");
        String cdcqtwt = request.getParameter("cdcqtwt");
        String yycqtwt = request.getParameter("yycqtwt");
        String qycqtwt = request.getParameter("qycqtwt");
        String hycqtwt = request.getParameter("hycqtwt");
        String wdtqtwt = request.getParameter("wdtqtwt");
        String ythqtwt = request.getParameter("ythqtwt");
        String csjqtwt = request.getParameter("csjqtwt");
        String zdwlqtwt = request.getParameter("zdwlqtwt");
        String jkjjgqtwt = request.getParameter("jkjjgqtwt");
        Xcxj xcxj = new Xcxj();
        xcxj.setCzmc(czmc);
        xcxj.setSsbm(ssbm);
        if (xcrqString != null && !"".equals(xcrqString)) {
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            xcxj.setXcrq(simpleDateFormat.parse(xcrqString));
        }
        xcxj.setXctq(xctq);
        xcxj.setXcry(xcry);
        xcxj.setXcrydh(xcrydh);
        xcxj.setClgy(clgy);
        xcxj.setJssl(jssl);
        xcxj.setCssl(cssl);
        xcxj.setSl(sl);
        xcxj.setPfkys(pfkys);
        xcxj.setPfkyw(pfkyw);
        xcxj.setGl(gl);
        xcxj.setKzg(kzg);
        xcxj.setFj(fj);
        xcxj.setFmj(fmj);
        xcxj.setTsb(tsb);
        xcxj.setHlb(hlb);
        xcxj.setLlj(llj);
        xcxj.setGdjfm(gdjfm);
        xcxj.setKzf(kzf);
        xcxj.setYwkzxt(ywkzxt);
        xcxj.setGsp(gsp);
        xcxj.setZxjksb(zxjksb);
        xcxj.setQtsb(qtsb);
        xcxj.setJsj(jsj);
        xcxj.setCdc(cdc);
        xcxj.setYyc(yyc);
        xcxj.setQyc(qyc);
        xcxj.setHyc(hyc);
        xcxj.setWdt(wdt);
        xcxj.setRgsdmsqk(rgsdmsqk);
        xcxj.setRgsdsfds(rgsdsfds);
        xcxj.setRgsdzwszqk(rgsdzwszqk);
        xcxj.setRgsdqtwt(rgsdqtwt);
        xcxj.setYthclss(ythclss);
        xcxj.setCsj(csj);
        xcxj.setCdhj(cdhj);
        xcxj.setZdwl(zdwl);
        xcxj.setGljkjjg(gljkjjg);
        xcxj.setQtss(qtss);
        xcxj.setGd(gd);
        xcxj.setWsj(wsj);
        xcxj.setTsbz(tsbz);
        xcxj.setJhg(jhg);
        xcxj.setJhj(jhj);
        xcxj.setHyhfc(hyhfc);
        xcxj.setCfqsj(cfqsj);
        xcxj.setDl(dl);
        xcxj.setQtwt(qtwt);
        xcxj.setGlqtwt(glqtwt);
        xcxj.setKzgqtwt(kzgqtwt);
        xcxj.setFjqtwt(fjqtwt);
        xcxj.setFmqtwt(fmqtwt);
        xcxj.setTsbqtwt(tsbqtwt);
        xcxj.setHlbqtwt(hlbqtwt);
        xcxj.setLljqtwt(lljqtwt);
        xcxj.setGdjfmqtwt(gdjfmqtwt);
        xcxj.setCdcqtwt(cdcqtwt);
        xcxj.setYycqtwt(yycqtwt);
        xcxj.setQycqtwt(qycqtwt);
        xcxj.setHycqtwt(hycqtwt);
        xcxj.setWdtqtwt(wdtqtwt);
        xcxj.setYthqtwt(ythqtwt);
        xcxj.setCsjqtwt(csjqtwt);
        xcxj.setZdwlqtwt(zdwlqtwt);
        xcxj.setJkjjgqtwt(jkjjgqtwt);
        xcxj.setId(UUID.randomUUID().toString());
        xcxjMapper.insertXcxj(xcxj);
        return json(true);
    }


    @RequestMapping(value = "/updateXjxc", method = RequestMethod.POST)
    public ModelAndView updateXjxc(HttpServletRequest request) throws ParseException {
        String czmc = request.getParameter("czmc");
        String ssbm = request.getParameter("ssbm");
        String xcrqString = request.getParameter("xcrqString");
        String xctq = request.getParameter("xctq");
        String xcry = request.getParameter("xcry");
        String xcrydh = request.getParameter("xcrydh");
        String clgy = request.getParameter("clgy");
        String jssl = request.getParameter("jssl");
        String cssl = request.getParameter("cssl");
        String sl = request.getParameter("sl");
        String pfkys = request.getParameter("pfkys");
        String pfkyw = request.getParameter("pfkyw");
        String gl = request.getParameter("gl");
        String kzg = request.getParameter("kzg");
        String fj = request.getParameter("fj");
        String fmj = request.getParameter("fmj");
        String tsb = request.getParameter("tsb");
        String hlb = request.getParameter("hlb");
        String llj = request.getParameter("llj");
        String gdjfm = request.getParameter("gdjfm");
        String kzf = request.getParameter("kzf");
        String ywkzxt = request.getParameter("ywkzxt");
        String gsp = request.getParameter("gsp");
        String zxjksb = request.getParameter("zxjksb");
        String qtsb = request.getParameter("qtsb");
        String jsj = request.getParameter("jsj");
        String cdc = request.getParameter("cdc");
        String yyc = request.getParameter("yyc");
        String qyc = request.getParameter("qyc");
        String hyc = request.getParameter("hyc");
        String wdt = request.getParameter("wdt");
        String rgsdmsqk = request.getParameter("rgsdmsqk");
        String rgsdsfds = request.getParameter("rgsdsfds");
        String rgsdzwszqk = request.getParameter("rgsdzwszqk");
        String rgsdqtwt = request.getParameter("rgsdqtwt");
        String ythclss = request.getParameter("ythclss");
        String csj = request.getParameter("csj");
        String cdhj = request.getParameter("cdhj");
        String zdwl = request.getParameter("zdwl");
        String gljkjjg = request.getParameter("gljkjjg");
        String qtss = request.getParameter("qtss");
        String gd = request.getParameter("gd");
        String wsj = request.getParameter("wsj");
        String tsbz = request.getParameter("tsbz");
        String jhg = request.getParameter("jhg");
        String jhj = request.getParameter("jhj");
        String hyhfc = request.getParameter("hyhfc");
        String cfqsj = request.getParameter("cfqsj");
        String dl = request.getParameter("dl");
        String qtwt = request.getParameter("qtwt");
        String glqtwt = request.getParameter("glqtwt");
        String kzgqtwt = request.getParameter("kzgqtwt");
        String fjqtwt = request.getParameter("fjqtwt");
        String fmqtwt = request.getParameter("fmqtwt");
        String tsbqtwt = request.getParameter("tsbqtwt");
        String hlbqtwt = request.getParameter("hlbqtwt");
        String lljqtwt = request.getParameter("lljqtwt");
        String gdjfmqtwt = request.getParameter("gdjfmqtwt");
        String cdcqtwt = request.getParameter("cdcqtwt");
        String yycqtwt = request.getParameter("yycqtwt");
        String qycqtwt = request.getParameter("qycqtwt");
        String hycqtwt = request.getParameter("hycqtwt");
        String wdtqtwt = request.getParameter("wdtqtwt");
        String ythqtwt = request.getParameter("ythqtwt");
        String csjqtwt = request.getParameter("csjqtwt");
        String zdwlqtwt = request.getParameter("zdwlqtwt");
        String jkjjgqtwt = request.getParameter("jkjjgqtwt");
        Xcxj xcxj = new Xcxj();
        xcxj.setCzmc(czmc);
        xcxj.setSsbm(ssbm);
        if (xcrqString != null && !"".equals(xcrqString)) {
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            xcxj.setXcrq(simpleDateFormat.parse(xcrqString));
        }
        xcxj.setXctq(xctq);
        xcxj.setXcry(xcry);
        xcxj.setXcrydh(xcrydh);
        xcxj.setClgy(clgy);
        xcxj.setJssl(jssl);
        xcxj.setCssl(cssl);
        xcxj.setSl(sl);
        xcxj.setPfkys(pfkys);
        xcxj.setPfkyw(pfkyw);
        xcxj.setGl(gl);
        xcxj.setKzg(kzg);
        xcxj.setFj(fj);
        xcxj.setFmj(fmj);
        xcxj.setTsb(tsb);
        xcxj.setHlb(hlb);
        xcxj.setLlj(llj);
        xcxj.setGdjfm(gdjfm);
        xcxj.setKzf(kzf);
        xcxj.setYwkzxt(ywkzxt);
        xcxj.setGsp(gsp);
        xcxj.setZxjksb(zxjksb);
        xcxj.setQtsb(qtsb);
        xcxj.setJsj(jsj);
        xcxj.setCdc(cdc);
        xcxj.setYyc(yyc);
        xcxj.setQyc(qyc);
        xcxj.setHyc(hyc);
        xcxj.setWdt(wdt);
        xcxj.setRgsdmsqk(rgsdmsqk);
        xcxj.setRgsdsfds(rgsdsfds);
        xcxj.setRgsdzwszqk(rgsdzwszqk);
        xcxj.setRgsdqtwt(rgsdqtwt);
        xcxj.setYthclss(ythclss);
        xcxj.setCsj(csj);
        xcxj.setCdhj(cdhj);
        xcxj.setZdwl(zdwl);
        xcxj.setGljkjjg(gljkjjg);
        xcxj.setQtss(qtss);
        xcxj.setGd(gd);
        xcxj.setWsj(wsj);
        xcxj.setTsbz(tsbz);
        xcxj.setJhg(jhg);
        xcxj.setJhj(jhj);
        xcxj.setHyhfc(hyhfc);
        xcxj.setCfqsj(cfqsj);
        xcxj.setDl(dl);
        xcxj.setQtwt(qtwt);
        xcxj.setGlqtwt(glqtwt);
        xcxj.setKzgqtwt(kzgqtwt);
        xcxj.setFjqtwt(fjqtwt);
        xcxj.setFmqtwt(fmqtwt);
        xcxj.setTsbqtwt(tsbqtwt);
        xcxj.setHlbqtwt(hlbqtwt);
        xcxj.setLljqtwt(lljqtwt);
        xcxj.setGdjfmqtwt(gdjfmqtwt);
        xcxj.setCdcqtwt(cdcqtwt);
        xcxj.setYycqtwt(yycqtwt);
        xcxj.setQycqtwt(qycqtwt);
        xcxj.setHycqtwt(hycqtwt);
        xcxj.setWdtqtwt(wdtqtwt);
        xcxj.setYthqtwt(ythqtwt);
        xcxj.setCsjqtwt(csjqtwt);
        xcxj.setZdwlqtwt(zdwlqtwt);
        xcxj.setJkjjgqtwt(jkjjgqtwt);
        String id = request.getParameter("id");
        xcxj.setId(id);
        xcxjMapper.updateXcxj(xcxj);
        return json(true);
    }

    @RequestMapping(value = "/getSzjcByCun", method = RequestMethod.GET)
    public ModelAndView getSzjcByCun(HttpServletRequest request) {
        String cun = request.getParameter("cun");
        Szjc szjc = szjcMapper.seleOneByTime(cun);
        return json(szjc);
    }

    @RequestMapping(value = "/getYhjlBycun", method = RequestMethod.POST)
    public ModelAndView getYhjlBycun(HttpServletRequest request) {
        String cun = request.getParameter("cun");
        String startTime = request.getParameter("begin");
        String endTime = request.getParameter("end");
        Calendar cal = Calendar.getInstance();
        if (startTime == null || "".equals(startTime)) {
            startTime = String.valueOf(cal.get(Calendar.YEAR));
            startTime = startTime + "-01-01";
        }
        if (endTime == null || "".equals(endTime)) {
            endTime = String.valueOf(cal.get(Calendar.YEAR)) + "-12-31";
        }
        List<Yhjl> list = yhjlMapper.selectOneByTime(cun, startTime, endTime);
        for (Yhjl yhjl : list) {
            if (yhjl.getYhrq() != null) {
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
                yhjl.setYhrqString(simpleDateFormat.format(yhjl.getYhrq()));
            }
        }
        return json(list);
    }

    @RequestMapping(value = "/getWxjlBycun", method = RequestMethod.POST)
    public ModelAndView getWxjlBycun(HttpServletRequest request) {
        String cun = request.getParameter("cun");
        String startTime = request.getParameter("begin");
        String endTime = request.getParameter("end");
        Calendar cal = Calendar.getInstance();
        if (startTime == null || "".equals(startTime)) {
            startTime = String.valueOf(cal.get(Calendar.YEAR));
            startTime = startTime + "-01-01";
        }
        if (endTime == null || "".equals(endTime)) {
            endTime = String.valueOf(cal.get(Calendar.YEAR)) + "-12-31";
        }
        List<Wxss> list = wxssMapper.selectOneBytime(cun, startTime, endTime);
        for (Wxss wxss : list) {
            if (wxss.getWxrq() != null) {
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
                wxss.setWxrqSting(simpleDateFormat.format(wxss.getWxrq()));
            }
        }
        return json(list);
    }

    @RequestMapping(value = "/getDtuSendList", method = RequestMethod.GET)
    public ModelAndView getDtuSendList(HttpServletRequest request) {
        JSONObject jsonObject = new JSONObject();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        int total = 0;
        String page = request.getParameter("page");
        String limit = request.getParameter("limit");
        //List<String> list = new ArrayList<String>();
        String key = request.getParameter("key");
        List<String> ids = dtuRecordMapper.selectListTidBySearch(key);
        Integer limits = Integer.valueOf(limit);
        Integer pages = Integer.valueOf(page);
        Integer pageIndex = (pages - 1) * limits;
        Integer pageSize = Integer.valueOf(limit);
        List<DtuRecord> list = new ArrayList<>();
        jsonObject.put("code", 0);
        if (ids.size() > 0) {
            list = dtuRecordMapper.findPagingByListTid(ids, pageIndex, pageSize);
            for (DtuRecord dtuRecord : list) {
                if (dtuRecord.getSendTime() != null && !"".equals(dtuRecord.getSendTime())) {
                    dtuRecord.setSendTimeString(sdf.format(dtuRecord.getSendTime()));
                }
            }
            jsonObject.put("data", list);
            jsonObject.put("count", ids.size());
            jsonObject.put("msg", "");
            return json(jsonObject);
        } else {
            jsonObject.put("data", list);
            jsonObject.put("count", 0);
            jsonObject.put("msg", "");
            return json(jsonObject);
        }

    }


    private ModelAndView json(Object result) {
        return new ModelAndView("jsonView").addObject("result", result);
    }
}
